bool Fruit::useEquipment(Equipment *equipment, Entity *target) { if (((equipment->getType() >= EQUIPMENT_TEA_SPOON) && (equipment->getType() <= EQUIPMENT_SALT_SNIPER)) || ((equipment->getType() == EQUIPMENT_JUICE_NEEDLE))) { Weapon *weapon = (Weapon*)equipment; return weapon->use(target); } else if (equipment->getType() == EQUIPMENT_PEELER) { Peeler *peeler = (Peeler*)equipment; return peeler->use(target); } else if (equipment->getType() == EQUIPMENT_RELOADER) { Loader *loader = (Loader*)equipment; return loader->use(target); } return false; }
// Get the next free weapon of this 'type' Weapon* SimpleStoresMgr::getSpecificWeapon(const std::type_info& type) { Weapon* wpn = nullptr; base::PairStream* list = getWeapons(); if (list != nullptr) { // Find the first free (inactive) bomb base::List::Item* item = list->getFirstItem(); while (item != nullptr && wpn == nullptr) { base::Pair* pair = static_cast<base::Pair*>(item->getValue()); Weapon* p = dynamic_cast<Weapon*>(pair->object()); if (p != nullptr && p->isInactive() && p->isClassType(type)) { p->ref(); wpn = p; } item = item->getNext(); } list->unref(); } return wpn; }
void NetPlayer::SetShip(Ship* s) { if (ship != s) { if (ship) { ship->EnableRepair(true); Ignore(ship); } ship = s; if (ship) { Observe(ship); ship->SetNetworkControl(this); ship->SetObjID(objid); iff = ship->GetIFF(); // Turn off auto-repair. All repair data should // come in over the network from the remote player: ship->EnableRepair(false); // Set all ship weapons back to manual fire control. // All trigger events should come over the network, // not from weapon auto aiming ai: ListIter<WeaponGroup> iter = ship->Weapons(); while (++iter) { WeaponGroup* group = iter.value(); ListIter<Weapon> w_iter = group->GetWeapons(); while (++w_iter) { Weapon* weapon = w_iter.value(); weapon->SetFiringOrders(Weapon::MANUAL); } } } } }
void CharacterCore::addSpell(SpellID id, int slotNr) { Weapon* wep = dynamic_cast<Weapon*>(m_equippedItems.at(ItemType::Equipment_weapon)); if (wep == nullptr) return; if (!wep->isSpellAllowed(slotNr, id)) return; // check if this spell is already in another slot, if yes, remove that for (auto& it : m_data.equippedWeaponSlots) { if (it.first == id) { it.first = SpellID::VOID; it.second.clear(); } } while (m_data.equippedWeaponSlots.size() - 1 < slotNr) { m_data.equippedWeaponSlots.push_back(std::pair<SpellID, std::vector<SpellModifier>>({SpellID::VOID, std::vector<SpellModifier>()})); } m_data.equippedWeaponSlots.at(slotNr).first = id; m_data.equippedWeaponSlots.at(slotNr).second.clear(); reloadWeaponSlots(); }
int main() { { Weapon club = Weapon("crude spiked club"); HumanA bob("Bob", club); bob.attack(); club.setType("some other type of club"); bob.attack(); } { Weapon club = Weapon("crude spiked club"); HumanB jim("Jim"); jim.setWeapon(club); jim.attack(); club.setType("some other type of club"); jim.attack(); } return 0; }
void Ship::fire(int weaponIndex) { if (weaponIndex >= 0 && weaponIndex < (int)weapons_.size()) { transform_->getMatrix(weaponTransformation_, false); //keeping weapon's local direction Weapon* weapon = weapons_[weaponIndex].first; weapon->currentDirection = weapon->direction; weapon->currentDirection.rotateVector(weaponTransformation_); //keeping weapon's local position Vector3 weaponPos = weapons_[weaponIndex].second; weaponPos.rotateVector(weaponTransformation_); weapon->position = transform_->getPosition() + weaponPos; weapon->fire(); } else Logger::PrintWarning("Ship::fire - invalid argument\n"); }
void CharacterCore::addModifier(const SpellModifier& modifier, int slotNr) { Weapon* wep = dynamic_cast<Weapon*>(m_equippedItems.at(ItemType::Equipment_weapon)); if (wep == nullptr) return; if (wep->addModifier(slotNr, modifier, true)) { std::pair<SpellID, std::vector<SpellModifier>>& slot = m_data.equippedWeaponSlots.at(slotNr); // check if this type already exists. if yes, remove it. for (auto& it = slot.second.begin(); it != slot.second.end(); /* don't increment here */) { if (it->type == modifier.type) { it = slot.second.erase(it); } else ++it; } slot.second.push_back(modifier); } reloadWeaponSlots(); }
void SideScroller::Update(float elapsed) { if (state == STATE_TITLE) { return; } else if (state == STATE_GAME) { if (enemySpawnTimer > 0.8f && enemies.size() < 50) { Enemy* tempEnemy = new PewRunner(tex); tempEnemy->y = player->y + 4.0f; tempEnemy->x = player->x + 10.0f; tempEnemy->setScale(2.5f); if (genRandomNumber(0.0f, 1.0f) > 0.93f) { //Grant him knighthood tempEnemy->hp += 30; Weapon* weapon = new Weapon(tex); weapon->changeWeapon(SWORD); tempEnemy->equip(weapon); entities.push_back(weapon); } tempEnemy->setWalkLeft(0.8f); enemies.push_back(tempEnemy); entities.push_back(tempEnemy); enemySpawnTimer = genRandomNumber(0.0f, 0.75f); } for (size_t i = 0; i < entities.size(); i++) { entities[i]->Update(elapsed); } for (size_t i = 0; i < projectiles.size(); i++) { projectiles[i]->Update(elapsed); } enemySpawnTimer += elapsed; } }
//do_zap: Perform a zap with a wand bool do_zap() { Coord delta; if (!get_dir(&delta)) return false; Item *item = get_item("zap with", STICK); if (!item) return false; Stick* stick = dynamic_cast<Stick*>(item); Weapon* weapon = dynamic_cast<Weapon*>(item); if (!(stick || (weapon && weapon->is_vorpalized() && weapon->charges()))) { //mdk: zapping with non-stick doesn't count as turn msg("you can't zap with that!"); return false; } // Handle the special case of a vorpalized weapon if (weapon) { game->screen().play_sound("zap"); if (weapon->zap_vorpalized_weapon(delta)) { weapon->use_charge(); } return true; } // Zap the appropriate stick if (stick->charges() == 0) { msg("nothing happens"); } else{ game->screen().play_sound("zap"); if (stick->Zap(delta)) { stick->use_charge(); } } return true; }
void Obstacle::Run(Weapon &weapon1,Player &player1,Weapon &weapon2,Player &player2) { double b1x=weapon1.GetBullet()->x(); double b1y=weapon1.GetBullet()->y(); int p1x=player1.getX(); int p1y=player1.getY(); double b2x=weapon2.GetBullet()->x(); double b2y=weapon2.GetBullet()->y(); int p2x=player2.getX(); int p2y=player2.getY(); Draw(p1x,p1y,p2x,p2y); Move(); CheckCollision(b1x,b1y,b2x,b2y); if (hstate1==1) { player1.health-=0.2; hstate1=0; } if (hstate2==1) { player2.health-=0.2; hstate2=0; } if (state1==1) { countdown+=0.9; if (countdown>1.2) { state1=0; countdown=0; } } if (state2==1) { countdown+=0.9; if (countdown>1.2) { state2=0; countdown=0; } } }
void StatusEffectsHandler::tryAddEffectsFromWeapon(const Weapon& wpn, const bool IS_MELEE) { const ItemDefinition& wpnDef = wpn.getDef(); StatusEffect* wpnEffect = IS_MELEE ? wpnDef.meleeStatusEffect : wpnDef.rangedStatusEffect; if(wpnEffect != NULL) { //Make a new copy of the weapon effect StatusEffect* cpy = wpnEffect->copy(); //Attempt to add the effect to the actor. //If attempt fails (saving throw succeeds, immune, etc), the copy is destroyed. tryAddEffect(cpy); } }
void DebriefMenu::handleGameEvent(GameEvent evt) { if (evt.type_ == GameEvent::GE_SEARCH) { // A research has ended, so check which type Research *pRes = static_cast<Research *> (evt.pCtxt_); // Is it equipment or mods research? if (pRes->getType() == Research::EQUIPS) { // Get researched weapon type Weapon::WeaponType wt= pRes->getSearchWeapon(); assert(wt); // Get weapon Weapon *pWeap = g_App.weapons().getWeapon(wt); assert(pWeap); // Draw name of it getStatic(txtSearchId_)->setTextFormated("#DEBRIEF_SEARCH", pWeap->getName()); } else { // Must be mods research so draw it getStatic(txtSearchId_)->setTextFormated("#DEBRIEF_SEARCH", pRes->getName().c_str()); } } }
bool StarshipAI::AssessTargetPointDefense() { if (Game::GameTime() - point_defense_time < 3500) return tgt_point_defense; tgt_point_defense = false; if (!target || target->Type() != SimObject::SIM_SHIP || GetAILevel() < 2) return tgt_point_defense; Ship* tgt_ship = (Ship*) target; if (!tgt_ship->IsStarship()) return tgt_point_defense; Weapon* subtgt = 0; Point svec = ship->Location() - tgt_ship->Location(); point_defense_time = Game::GameTime(); // first pass: turrets ListIter<WeaponGroup> g_iter = tgt_ship->Weapons(); while (++g_iter && !tgt_point_defense) { WeaponGroup* g = g_iter.value(); if (g->CanTarget(1)) { ListIter<Weapon> w_iter = g->GetWeapons(); while (++w_iter && !tgt_point_defense) { Weapon* w = w_iter.value(); if (w->Availability() > 35 && w->GetAimVector() * svec > 0) tgt_point_defense = true; } } } return tgt_point_defense; }
int WeaponGroup::Status() const { int status = System::NOMINAL; int critical = true; ListIter<Weapon> iter = (List<Weapon>&) weapons; // cast-away const while (++iter) { Weapon* w = iter.value(); if (w->Status() < System::NOMINAL) status = System::DEGRADED; if (w->Status() > System::CRITICAL) critical = false; } if (critical) return System::CRITICAL; return status; }
// Enter the state void PlayerReloadingState::enter(PlayerUnit *ref) { ASSERT(ref->getActualWeapon()); Weapon *w = ref->getActualWeapon(); // depending of the weapon, we will get the animation switch(w->getType()){ case Weapon::W_SHORT: ref->changeAnimation(PlayerUnit::ANIM_RELOAD_SHORT); break; case Weapon::W_LONG: ref->changeAnimation(PlayerUnit::ANIM_RELOAD_LONG); break; default: ASSERT(false); } ASSERT(w->getAmmunition() > 0); }
//-------------------------------------------------------------- // // Name: G_DropItemCmd // Class: None // // Description: Drops an item that is clicked on from the inventory // // Parameters: gentity_t -- the entity issuing the command. This // is the player who issued the command. // // Returns: qboolean -- true if the command was executed. // //-------------------------------------------------------------- qboolean G_DropItemCmd( const gentity_t *ent ) { if ( gi.argc() < 1 ) return false ; if ( !ent->entity->isSubclassOf( Player ) ) return false ; Player *player = (Player*)ent->entity ; str objectName = gi.argv( 1 ); str propertyName = gi.argv( 2 ); GameplayManager *gpm = GameplayManager::getTheGameplayManager(); if ( !gpm ) return false ; str itemName = gpm->getStringValue( objectName, propertyName ); if ( itemName == "Empty" ) return false; str tikiName = gpm->getStringValue( itemName, "model" ); str itemType = gpm->getStringValue( itemName, "class" ); str playerItem("CurrentPlayer." + itemType); if ( !gpm->hasObject(playerItem) ) { gi.WPrintf( "Warning: Unknown item type %s for item %s", itemType.c_str(), itemName.c_str() ); return false ; } // Empty the slot gpm->setStringValue( objectName, propertyName, "Empty" ); // Give the player the item to drop //Item *givenItem = player->giveItem(tikiName); Weapon *dropweap; ClassDef *cls; cls = getClass( tikiName.c_str() ); if ( !cls ) { SpawnArgs args; args.setArg( "model", tikiName.c_str() ); cls = args.getClassDef(); if ( !cls ) return false; } dropweap = ( Weapon * )cls->newInstance(); dropweap->setModel( tikiName.c_str() ); dropweap->ProcessPendingEvents(); dropweap->SetOwner(player); dropweap->hideModel(); dropweap->setAttached(true); dropweap->Drop(); return true ; }
void BasicMonster::useBestWeapon() { bool melee = usesMeleeWeapons(); bool ranged = usesRangedWeapons(); int bestScore = -1; symbol bestWeapon = '\0'; for (auto it = inventory.begin(); it != inventory.end(); it++) { if (it->second->getType() != ITEM_WEAPON) continue; Weapon* weapon = static_cast<Weapon*>(it->second); if (weapon->getRange() <= 1 && !melee) continue; if (weapon->getRange() > 1 && !ranged) continue; int score = scoreWeapon(weapon); if (score > bestScore) { bestScore = score; bestWeapon = it->first; } } mainWeapon = bestWeapon; }
void Ship::prevWeapon() { weapon->stopShooting(); int current = 0; for(int i = 0; i < weapons.size(); ++i) { if(weapons.at(i) == weapon) { current = i; break; } } for(int i = weapons.size() - 1; i > 0 ; --i) { Weapon* w = weapons.at((current + i) % weapons.size()); if(w->getLevel() > 0) { weapon = w; break; } } }
//--------------------------------------------------------------------------- void Avatar::fireWeaponGroup(int /*groupId*/) { // for now, fire everything ComponentList list; findComponents(EquipmentSlotComponent::getClassDef(), list); for (ComponentList::iterator it = list.begin(); it != list.end(); ++it) { EquipmentSlotComponent* pSlot = static_cast<EquipmentSlotComponent*>(*it); if (pSlot) { size_t numEquipment = pSlot->getNumEquipment(); for (size_t i=0; i<numEquipment; ++i) { Mountable* pMountable = pSlot->getEquipment(i); if (pMountable && pMountable->isOfType(Weapon::getClassDef())) { Weapon* pWeapon = static_cast<Weapon*>(pMountable); pWeapon->fire(); } } } } }
void RuneAmmoRegen::specificUpdate( float frameTime ) { str ammoType; Weapon *weapon; Q_UNUSED(frameTime); if ( _owner && ( level.time > _nextGiveTime ) && _owner->isSubclassOf( Player ) ) { Player *player = (Player *)_owner; weapon = player->GetActiveWeapon( WEAPON_DUAL ); if ( weapon ) { ammoType = weapon->GetAmmoType( FIRE_MODE1 ); player->GiveAmmo( ammoType, 1, false ); } _nextGiveTime = level.time + 1.0f; } }
Entity *Message::ExtractEntity() { if (message_type_ == kEntityDataMessage || message_type_ == kViewUpdateMessage) { boost::uuids::uuid source = ExtractUuid(); std::string name = ExtractString(); int health_value = ExtractInt(); int health_bound = ExtractInt(); BoundedAttribute health(health_value, health_bound); Entity *entity = new Entity(name, health); entity->AssignId(source); std::string weapon_name = ExtractString(); int value = ExtractInt(); int min_damage = ExtractInt(); int max_damage = ExtractInt(); Weapon *weapon = new Weapon(weapon_name, value, min_damage, max_damage); weapon->Equip(*entity); return entity; } return NULL; }
GameObj* GOBox::shoot() { if (getIsWeapon()) { Weapon* w = getWeapon(); if (getIsRangedWeapon()){ if (((RangedWeapon *)w)->readyToShoot()) { double rbDepth = getDepth() / 2 + ((RangedWeapon *)w)->getPDepth()/1.5 + 0.6f; btTransform* rbTrans = &getRigidBody()->getWorldTransform(); btVector3 boxRot = rbTrans->getBasis()[2]; boxRot.normalize(); btVector3 correctedDisplacement = boxRot * -rbDepth; // /2 double x = rbTrans->getOrigin().getX();// + 0.5 - w->getPWidth(); double y = rbTrans->getOrigin().getY(); double z = rbTrans->getOrigin().getZ() + correctedDisplacement.getZ(); GameObj* proj = new Projectile(x, y, z, rbTrans->getRotation().getX(), rbTrans->getRotation().getY(), rbTrans->getRotation().getZ(), rbTrans->getRotation().getW(), ((RangedWeapon *)w)->getPMass(), ((RangedWeapon *)w)->getPWidth(), ((RangedWeapon *)w)->getPHeight(), ((RangedWeapon *)w)->getPDepth()); proj->setDamage(w->getDamage()); //std::cout << "shoot: " << ((RangedWeapon *)w)->getPBlockType() << std::endl; proj->setBlockType(((RangedWeapon *)w)->getPBlockType()); ((RangedWeapon *)w)->setLastShot(); ((Projectile*)proj)->initForce = ((RangedWeapon *)w)->getPInitForce(); return proj; } } } return nullptr; }
/// <summary> /// Builder of the Weapons class use to copy /// </summary> /// <param> weaponToCopy: The weapon's to copy, what did you expected? </param> Weapon::Weapon(const Weapon& weaponToCopy) : Item(*(weaponToCopy.m_name), *weaponToCopy.m_type, weaponToCopy.m_itemImagePath.at(0), weaponToCopy.m_price) , m_weaponsDamage(weaponToCopy.m_weaponsDamage), m_weaponsKnockback(weaponToCopy.m_weaponsKnockback) { m_weaponType = new std::string(*weaponToCopy.m_weaponType); m_itemImagePath.push_back(weaponToCopy.m_itemImagePath.at(1)); m_itemImagePath.push_back(weaponToCopy.m_itemImagePath.at(2)); m_weaponsImage = new sf::Texture(*(weaponToCopy.m_weaponsImage)); m_weaponsSprite = new sf::Sprite(*m_weaponsImage); m_weaponsSprite->setPosition(weaponToCopy.getWeaponSprite().getPosition()); m_weaponsBox = new sf::FloatRect(m_weaponsSprite->getGlobalBounds()); m_weaponsAnimationTime = new sf::Time(*(weaponToCopy.m_weaponsAnimationTime)); m_weaponsKnockbackTime = new sf::Time(*(weaponToCopy.m_weaponsKnockbackTime)); m_weaponCoolDownTime = new sf::Time(*(weaponToCopy.m_weaponCoolDownTime)); }
bool CombatGameInst::melee_attack(GameState* gs, CombatGameInst* inst, const Weapon& weapon) { bool isdead = false; if (!cooldowns().can_doaction()) return false; MTwist& mt = gs->rng(); AttackStats attack(weapon); EffectiveAttackStats atkstats = effective_atk_stats(mt, AttackStats(weapon)); int damage = damage_formula(atkstats, inst->effective_stats()); if (dynamic_cast<PlayerInst*>(this) || !gs->game_settings().invincible) { isdead = inst->damage(gs, damage); } char dmgstr[32]; snprintf(dmgstr, 32, "%d", damage); float rx, ry; direction_towards(Pos(x, y), Pos(inst->x, inst->y), rx, ry, 0.5); gs->add_instance( new AnimatedInst(Pos(inst->x - 5 + rx * 5, inst->y + ry * 5), -1, 25, Posf(rx, ry), Posf(), AnimatedInst::DEPTH, dmgstr, Colour(255, 148, 120))); cooldowns().reset_action_cooldown(atkstats.cooldown); cooldowns().action_cooldown += gs->rng().rand(-4, 5); WeaponEntry wentry = weapon.weapon_entry(); if (wentry.name != "none") { gs->add_instance( new AnimatedInst(inst->pos(), wentry.attack_sprite, 25)); } signal_attacked_successfully(); return isdead; }
Weapon::Weapon(const Weapon& other) { mOwner = other.mOwner; mBody = other.mBody; mFireAng = other.mFireAng; mFireForce = other.mFireForce; mLiveTime = other.mLiveTime; mDestroyed = other.mDestroyed; setWorld(other.getWorld()); if (mBody) { mBody->SetUserData(this); auto fix = mBody->GetFixtureList(); do { fix->SetUserData(this); } while (fix = fix->GetNext()); } }
void Turret::fireProjectile(const FBox &target_box, const Weapon &weapon, float randomness) { if(isClient()) return; Segment best_ray = computeBestShootingRay(target_box, weapon); if(randomness > 0.0f) { float3 dir = perturbVector(best_ray.dir(), random(), random(), randomness); best_ray = Ray(best_ray.origin(), dir); } #ifdef DEBUG_SHOOTING { m_aiming_lines.clear(); m_aiming_lines.push_back(best_ray.origin()); Intersection isect = trace(best_ray, {Flags::all | Flags::colliding, ref()}); m_aiming_lines.push_back(best_ray.origin() + best_ray.dir() * isect.distance()); } #endif //TODO: spawned projectiles should be centered if( const ProjectileProto *proj_proto = weapon.projectileProto() ) addNewEntity<Projectile>(best_ray.origin(), *proj_proto, actualDirAngle(), best_ray.dir(), ref(), weapon.proto().damage_mod); }
void Attack::printMeleeMsgAndPlaySfx(const MeleeAttackData& data, const Weapon& wpn) { string otherName = ""; if(data.isDefenderDodging) { //----- DEFENDER DODGES -------- if(data.attacker == eng.player) { if(eng.player->isSeeingActor(*data.curDefender, NULL)) { otherName = data.curDefender->getNameThe(); } else { otherName = "It "; } eng.log->addMsg(otherName + " dodges my attack."); } else { if(eng.player->isSeeingActor(*data.attacker, NULL)) { otherName = data.attacker->getNameThe(); } else { otherName = "It"; } eng.log->addMsg("I dodge an attack from " + otherName + ".", clrMsgGood); } } else if(data.attackResult <= failSmall) { //----- BAD AIMING -------- if(data.attacker == eng.player) { if(data.attackResult == failSmall) { eng.log->addMsg("I barely miss!"); } else if(data.attackResult == failNormal) { eng.log->addMsg("I miss."); } else if(data.attackResult == failBig) { eng.log->addMsg("I miss completely."); } Audio::play(wpn.getData().meleeMissSfx); } else { if(eng.player->isSeeingActor(*data.attacker, NULL)) { otherName = data.attacker->getNameThe(); } else { otherName = "It"; } if(data.attackResult == failSmall) { eng.log->addMsg(otherName + " barely misses me!", clrWhite, true); } else if(data.attackResult == failNormal) { eng.log->addMsg(otherName + " misses me.", clrWhite, true); } else if(data.attackResult == failBig) { eng.log->addMsg(otherName + " misses me completely.", clrWhite, true); } } } else { //----- AIM IS CORRECT ------- if(data.isEtherealDefenderMissed) { //----- ATTACK MISSED DUE TO ETHEREAL TARGET -------- if(data.attacker == eng.player) { if(eng.player->isSeeingActor(*data.curDefender, NULL)) { otherName = data.curDefender->getNameThe(); } else { otherName = "It "; } eng.log->addMsg( "My attack passes right through " + otherName + "!"); } else { if(eng.player->isSeeingActor(*data.attacker, NULL)) { otherName = data.attacker->getNameThe(); } else { otherName = "It"; } eng.log->addMsg( "The attack of " + otherName + " passes right through me!", clrMsgGood); } } else { //----- ATTACK CONNECTS WITH DEFENDER -------- //Determine the relative "size" of the hit MeleeHitSize hitSize = MeleeHitSize::small; const int MAX_DMG_ROLL = data.dmgRolls * data.dmgSides; if(MAX_DMG_ROLL >= 4) { if(data.dmgRoll > (MAX_DMG_ROLL * 5) / 6) { hitSize = MeleeHitSize::hard; } else if(data.dmgRoll > MAX_DMG_ROLL / 2) { hitSize = MeleeHitSize::medium; } } //Punctuation depends on attack strength string dmgPunct = "."; switch(hitSize) { case MeleeHitSize::small: break; case MeleeHitSize::medium: dmgPunct = "!"; break; case MeleeHitSize::hard: dmgPunct = "!!!"; break; } if(data.attacker == eng.player) { const string wpnVerb = wpn.getData().meleeAttMsgs.player; if(eng.player->isSeeingActor(*data.curDefender, NULL)) { otherName = data.curDefender->getNameThe(); } else { otherName = "it"; } if(data.isIntrinsicAttack) { const string ATTACK_MOD_STR = data.isWeakAttack ? " feebly" : ""; eng.log->addMsg( "I " + wpnVerb + " " + otherName + ATTACK_MOD_STR + dmgPunct, clrMsgGood); } else { const string ATTACK_MOD_STR = data.isWeakAttack ? "feebly " : data.isBackstab ? "covertly " : ""; const SDL_Color clr = data.isBackstab ? clrBlueLgt : clrMsgGood; const string wpnName_a = eng.itemDataHandler->getItemRef(wpn, ItemRefType::a, true); eng.log->addMsg( "I " + wpnVerb + " " + otherName + " " + ATTACK_MOD_STR + "with " + wpnName_a + dmgPunct, clr); } } else { const string wpnVerb = wpn.getData().meleeAttMsgs.other; if(eng.player->isSeeingActor(*data.attacker, NULL)) { otherName = data.attacker->getNameThe(); } else { otherName = "It"; } eng.log->addMsg(otherName + " " + wpnVerb + dmgPunct, clrMsgBad, true); } SfxId hitSfx = SfxId::endOfSfxId; switch(hitSize) { case MeleeHitSize::small: { hitSfx = wpn.getData().meleeHitSmallSfx; } break; case MeleeHitSize::medium: { hitSfx = wpn.getData().meleeHitMediumSfx; } break; case MeleeHitSize::hard: { hitSfx = wpn.getData().meleeHitHardSfx; } break; } Audio::play(hitSfx); } } }
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); }
void SelectMenu::drawAgent() { Agent *selected = g_Session.agents().squadMember(cur_agent_); if (selected == NULL) return; int torso, arms, legs; int armsx = 188; int armsy = 152; int torsoy = 116; int legsy = 218; if (selected->isMale()) { torso = 30; arms = 40; legs = 32; } else { torso = 31; arms = 44; legs = 36; armsx += 10; armsy += 6; torsoy += 2; legsy -= 4; } if (selected->slot(Mod::MOD_LEGS)) { legs = selected->slot(Mod::MOD_LEGS)->icon(selected->isMale()); getMenuFont(FontManager::SIZE_1)->drawText(366, 250, selected->slot(Mod::MOD_LEGS)->getName(), false); } if (selected->slot(Mod::MOD_ARMS)) { arms = selected->slot(Mod::MOD_ARMS)->icon(selected->isMale()); getMenuFont(FontManager::SIZE_1)->drawText(366, 226, selected->slot(Mod::MOD_ARMS)->getName(), false); } menuSprites().drawSpriteXYZ(arms, armsx, armsy, 0, false, true); menuSprites().drawSpriteXYZ(torso, 224, torsoy, 0, false, true); menuSprites().drawSpriteXYZ(legs, 224, legsy, 0, false, true); if (selected->slot(Mod::MOD_CHEST)) { int chest = selected->slot(Mod::MOD_CHEST)->icon(selected->isMale()); getMenuFont(FontManager::SIZE_1)->drawText(366, 202, selected->slot(Mod::MOD_CHEST)->getName(), false); int chestx = 216; int chesty = 146; if (!selected->isMale()) { chestx += 8; chesty += 2; } menu_manager_->menuSprites().drawSpriteXYZ(chest, chestx, chesty, 0, false, true); } if (selected->slot(Mod::MOD_HEART)) { int heart = selected->slot(Mod::MOD_HEART)->icon(selected->isMale()); getMenuFont(FontManager::SIZE_1)->drawText(366, 160, selected->slot(Mod::MOD_HEART)->getName(), false); menu_manager_->menuSprites().drawSpriteXYZ(heart, 254, 166, 0, false, true); } if (selected->slot(Mod::MOD_EYES)) { int eyes = selected->slot(Mod::MOD_EYES)->icon(selected->isMale()); getMenuFont(FontManager::SIZE_1)->drawText(366, 136, selected->slot(Mod::MOD_EYES)->getName(), false); int eyesx = 238; if (!selected->isMale()) { eyesx += 2; } menuSprites().drawSpriteXYZ(eyes, eyesx, 116, 0, false, true); } if (selected->slot(Mod::MOD_BRAIN)) { int brain = selected->slot(Mod::MOD_BRAIN)->icon(selected->isMale()); getMenuFont(FontManager::SIZE_1)->drawText(366, 112, selected->slot(Mod::MOD_BRAIN)->getName(), false); int brainx = 238; if (!selected->isMale()) { brainx += 2; } menuSprites().drawSpriteXYZ(brain, brainx, 114, 0, false, true); } // restore lines over agent menu_manager_->blitFromBackground(254, 124, 30, 2); menu_manager_->blitFromBackground(264, 132, 30, 2); menu_manager_->blitFromBackground(266, 174, 36, 2); menu_manager_->blitFromBackground(252, 210, 56, 2); menu_manager_->blitFromBackground(302, 232, 10, 2); menu_manager_->blitFromBackground(264, 256, 30, 2); // write inventory for (int j = 0; j < 2; j++) for (int i = 0; i < 4 && (j * 4 + i < selected->numWeapons()); i++) { WeaponInstance *wi = selected->weapon(j * 4 + i); Weapon *pW = wi->getWeaponClass(); menuSprites().drawSpriteXYZ(pW->getSmallIconId(), 366 + i * 32, 308 + j * 32, 0, false, true); uint8 data[3] = {204, 204, 204}; if (pW->ammo() != -1) { int n = wi->ammoRemaining(); if (pW->ammo() == 0) n = 24; else { n *= 24; n /= pW->ammo(); } for (int k = 0; k < n; k++) g_Screen.scale2x(366 + i * 32 + k + 4, 308 + j * 32 + 22, 1, 3, data); } } }
//------------------------------------------------------------------------------ // Manage the weapon release event //------------------------------------------------------------------------------ bool SimpleStoresMgr::onWpnRelEvent(const base::Boolean* const sw) { // Weapon release follows the switch or by default is true bool wpnRel = true; if (sw != nullptr) wpnRel = sw->getBoolean(); if ( wpnRel && (isWeaponDeliveryMode(A2A) || isWeaponDeliveryMode(A2G)) ) { // A/A missiles and A/G bombs only ... Weapon* wpn = getCurrentWeapon(); if (wpn != nullptr) { // release the weapon --- // if successful, returns a pre-ref()'d pointer to the flyout weapon. Weapon* flyout = releaseWeapon(wpn); if (flyout != nullptr) { if (isWeaponDeliveryMode(A2A)) { // --- // Setup the guidance ... // --- Track* trk = getNextTarget(); if (trk != nullptr) { Player* tgt = trk->getTarget(); TrackManager* tm = nullptr; RfSensor* sm = flyout->getSensor(); if (sm != nullptr) tm = sm->getTrackManager(); if (tm != nullptr) { // Give a copy of the track to the weapon's track manager Track* newTrk = trk->clone(); tm->clearTracksAndQueues(); tm->addTrack(newTrk); flyout->setTargetTrack(newTrk,true); } else if (tgt != nullptr) { // No sensor -- fake it and just track the target flyout->setTargetPlayer(tgt,true); } else { // no target track } trk->setWeaponReleased(true); } } // Set the weapon release timer setWeaponReleaseTimer(1.0); } if (flyout != nullptr) flyout->unref(); // unref() the flyout wpn->unref(); wpn = nullptr; } } else { setWeaponReleaseTimer(0); } return true; }