Exemplo n.º 1
0
bool NpcManager::handleAttack(CreatureObject *attacker, uint64 targetId) // , ObjectControllerCmdProperties *cmdProperties)
{
    CreatureObject* defender = dynamic_cast<CreatureObject*>(gWorldManager->getObjectById(targetId));

    if (_verifyCombatState(attacker, targetId))
    {
        // get the current weapon
		Weapon* weapon = dynamic_cast<Weapon*>(gWorldManager->getObjectById(attacker->GetWeaponId()));

        if (!weapon)
        {
            return(false);
        }

        // do the attack
        /*uint8 attackResult = */_executeAttack(attacker, defender, weapon);

        return(true);
    }

    return(false);
}
Exemplo n.º 2
0
bool CombatManager::handleAttack(CreatureObject* attacker, uint64 targetId, ObjectControllerCmdProperties *cmdProperties)
{
    CreatureObject* defender = dynamic_cast<CreatureObject*>(gWorldManager->getObjectById(targetId));

    // get the current weapon
	//what if he/she/it is left handed ? what if he she it has multiple appendages with weapons ?
	Weapon* weapon = dynamic_cast<Weapon*>(gWorldManager->getObjectById(attacker->GetWeaponId()));
	
	//auto weapon = dynamic_cast<Weapon*>(gWorldManager->getKernel()->GetServiceManager()->GetService<swganh::equipment::EquipmentService>("EquipmentService")->GetEquippedObject(attacker, "hold_r"));
   
    if (!weapon)    {
        return(false);
    }

    if (!defender)    {
        return(false);
    }

    // NOTE: Some weapon data just for tesing and to give the npc a fair chance...
    uint32 weaponGroup = weapon->getGroup();
    float weaponRange = 6.0;

    //if (weaponGroup <= WeaponGroup_Polearm)
    //{
    //	weaponRange = 6.0;
    //}
    // else
    if (weaponGroup == WeaponGroup_Rifle)
    {
        weaponRange = 64.0;
    }
    else if (weaponGroup == WeaponGroup_Pistol)
    {
        weaponRange = 35.0;
    }
    else if (weaponGroup == WeaponGroup_Carbine)
    {
        weaponRange = 50.0;
    }
    //else
    //{
    //	weaponRange = 6.0;
    //}

    // if we are out of range, skip this attack.
    if (glm::distance(attacker->mPosition, defender->mPosition) > weaponRange)
    {
        // Target out of range.
        PlayerObject* playerAttacker = dynamic_cast<PlayerObject*>(attacker);
        if (playerAttacker && playerAttacker->isConnected())
        {
            gMessageLib->SendSystemMessage(::common::OutOfBand("error_message", "target_out_of_range"), playerAttacker);
        }
        // It's like you shoot but missed, maintain cooldown.
        // return true;
        return false;
    }

    if(_verifyCombatState(attacker,defender->getId()))
    {

        // Execute the attack
        /*uint8 attackResult = */_executeAttack(attacker,defender,cmdProperties,weapon);

        return(true);
    }

    return(false);
}