示例#1
0
void AFPSGCharacter::manageWeapon(AFPSGWeapon* in_weapon)
{
	bool weaponFound = isInInventory(in_weapon);

	//This weapon was found in the inventory, only add its ammunition
	if (weaponFound)
	{
		//GEngine->AddOnScreenDebugMessage(-1, 6.0f, FColor::Red, "weaponFound");

		AFPSGWeapon* weapon = findWeapon(in_weapon);

		if (weapon != NULL)
		{
			//GEngine->AddOnScreenDebugMessage(-1, 6.0f, FColor::Red, "Add ammunition");
			weapon->setCurrentAmmunition(weapon->getCurrentAmmunition() + in_weapon->getCurrentAmmunition());
		}
	}
	else //Otherwise, add the weapon
	{
		//GEngine->AddOnScreenDebugMessage(-1, 6.0f, FColor::Red, "weapon NOT found");

		//Spawn the weapon
		AFPSGWeapon* spawnedWeapon = spawnWeapon(in_weapon, FVector::ZeroVector, FRotator::ZeroRotator);

		//Disable the weapons collision component, attach to character and set to invisible, then add it to the inventory
		if (spawnedWeapon != NULL)
		{
			spawnedWeapon->getBoxCollisionComponent()->UnregisterComponent();
			spawnedWeapon->AttachRootComponentTo(GetMesh(), inventoryWeaponSocket, EAttachLocation::SnapToTarget);
			spawnedWeapon->SetActorHiddenInGame(true);
			addWeapon(spawnedWeapon);
		}
	}
}
示例#2
0
///////////////////
// Receive the list
void CWpnRest::readList(CBytestream *psByteS)
{
    std::string szName;
    int nState;
    wpnrest_t *psWpn = NULL;

    // Initialize all the weapons to a default of 'enabled'
    reset();

    int nCount = psByteS->readInt(2);

    // Go through the list reading weapons
    for( int i=0; i<nCount; i++ ) {
        szName = psByteS->readString();
        nState = psByteS->readByte();

        // Try and find the weapon
        psWpn = findWeapon(szName);
        if( psWpn )
            psWpn->nState = nState;
        else {
            // If the weapon doesn't exist, thats ok
            // just add it to the list
            addWeapon(szName,nState);
        }
    }
}
示例#3
0
///////////////////
// Get the state of a weapon
int CWpnRest::getWeaponState(const std::string& szName)
{
    wpnrest_t *psWpn = findWeapon(szName);

    // Default to disabled if we can't find the weapon
    if( !psWpn )
        return wpr_banned;

    return psWpn->nState;
}
示例#4
0
///////////////////
// Checks if the weapon is bonus or not
bool CWpnRest::isBonus(const std::string& szName)
{
    wpnrest_t *psWpn = findWeapon(szName);

    // If we can't find the weapon, then assume it is banned
    if( !psWpn )
        return false;

    return (psWpn->nState == wpr_bonus);
}
示例#5
0
///////////////////
// Update the weapons list from a gamescript file
void CWpnRest::updateList(const std::vector<std::string> & weaponList)
{
    // Go through the weapons in the gamescript
    // If any weapon is not in our list, add it to the list
    int count = weaponList.size();
    int i;


    for(i=0; i<count; i++) {

        wpnrest_t *w = findWeapon( weaponList[i] );
        if( !w ) {
            // No match, add it to the list
            addWeapon( weaponList[i], wpr_enabled );
        }
    }

    // Sort the list
    sortList();
}