void TreasuryManager::inventoryTipOnline(int32 amount, PlayerObject* playerObject,PlayerObject* targetObject ) { if(!targetObject) { gMessageLib->SendSystemMessage(::common::OutOfBand("base_player", "tip_error"), playerObject); return; } //check if we have enough money if(amount > dynamic_cast<Inventory*>(playerObject->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory))->getCredits()) { gMessageLib->SendSystemMessage(::common::OutOfBand("base_player", "prose_tip_nsf_cash", 0, targetObject->getId(), 0, amount), playerObject); return; } if( glm::distance(playerObject->mPosition, targetObject->mPosition) > 10.0) { gMessageLib->SendSystemMessage(::common::OutOfBand("base_player", "prose_tip_range", 0, targetObject->getId(), 0, amount), playerObject); return; } Inventory* playerInventory = dynamic_cast<Inventory*>(playerObject->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory)); Inventory* targetInventory = dynamic_cast<Inventory*>(targetObject->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory)); playerInventory->setCredits(playerInventory->getCredits() - amount); targetInventory->setCredits(targetInventory->getCredits() + amount); saveAndUpdateInventoryCredits(playerObject); saveAndUpdateInventoryCredits(targetObject); gMessageLib->SendSystemMessage(::common::OutOfBand("base_player", "prose_tip_pass_self", 0, targetObject->getId(), 0, amount), playerObject); gMessageLib->SendSystemMessage(::common::OutOfBand("base_player", "prose_tip_pass_target", 0, playerObject->getId(), 0, amount), targetObject); }
void PlayerStructure::handleUIEvent(BString strCharacterCash, BString strHarvesterCash, UIWindow* window) { PlayerObject* player = window->getOwner(); if(!player) { return; } switch(window->getWindowType()) { case SUI_Window_Deposit_Power: { strCharacterCash.convert(BSTRType_ANSI); BString characterPower = strCharacterCash; strHarvesterCash.convert(BSTRType_ANSI); BString harvesterPower = strHarvesterCash; int32 harvesterPowerDelta = atoi(harvesterPower.getAnsi()); gStructureManager->deductPower(player,harvesterPowerDelta); this->setCurrentPower(getCurrentPower()+harvesterPowerDelta); gWorldManager->getDatabase()->executeSqlAsync(0,0,"UPDATE %s.structure_attributes SET value='%u' WHERE structure_id=%" PRIu64 " AND attribute_id=384",gWorldManager->getDatabase()->galaxy(),getCurrentPower(),this->getId()); } break; case SUI_Window_Pay_Maintenance: { strCharacterCash.convert(BSTRType_ANSI); strHarvesterCash.convert(BSTRType_ANSI); Bank* bank = dynamic_cast<Bank*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Bank)); Inventory* inventory = dynamic_cast<Inventory*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory)); int32 bankFunds = bank->credits(); int32 inventoryFunds = inventory->getCredits(); int32 funds = inventoryFunds + bankFunds; int32 characterMoneyDelta = atoi(strCharacterCash.getAnsi()) - funds; int32 harvesterMoneyDelta = atoi(strHarvesterCash.getAnsi()) - this->getCurrentMaintenance(); // the amount transfered must be greater than zero if(harvesterMoneyDelta == 0 || characterMoneyDelta == 0) { return; } //lets get the money from the bank first if((bankFunds +characterMoneyDelta)< 0) { characterMoneyDelta += bankFunds; bankFunds = 0; inventoryFunds += characterMoneyDelta; } else { bankFunds += characterMoneyDelta; } if(inventoryFunds < 0) { return; } int32 maintenance = this->getCurrentMaintenance() + harvesterMoneyDelta; if(maintenance < 0) { return; } bank->credits(bankFunds); inventory->setCredits(inventoryFunds); gWorldManager->getDatabase()->destroyResult(gWorldManager->getDatabase()->executeSynchSql("UPDATE %s.banks SET credits=%u WHERE id=%" PRIu64 "",gWorldManager->getDatabase()->galaxy(),bank->credits(),bank->getId())); gWorldManager->getDatabase()->destroyResult(gWorldManager->getDatabase()->executeSynchSql("UPDATE %s.inventories SET credits=%u WHERE id=%" PRIu64 "",gWorldManager->getDatabase()->galaxy(),inventory->getCredits(),inventory->getId())); //send the appropriate deltas. gMessageLib->sendInventoryCreditsUpdate(player); gMessageLib->sendBankCreditsUpdate(player); //get the structures conditiondamage and see whether it needs repair uint32 damage = this->getDamage(); if(damage) { uint32 cost = this->getRepairCost(); uint32 all = cost*damage; if(maintenance <= (int32)all) { all -= (uint32)maintenance; damage = (uint32)(all/cost); maintenance = 0; } if(maintenance > (int32)all) { maintenance -= (int32)all; damage = 0; } //update the remaining damage in the db gWorldManager->getDatabase()->executeSqlAsync(0,0,"UPDATE %s.structures s SET s.condition= %u WHERE s.ID=%" PRIu64 "",gWorldManager->getDatabase()->galaxy(),damage,this->getId()); this->setDamage(damage); //Update the structures Condition gMessageLib->sendHarvesterCurrentConditionUpdate(this); } gWorldManager->getDatabase()->executeSqlAsync(0,0,"UPDATE %s.structure_attributes SET value='%u' WHERE structure_id=%" PRIu64 " AND attribute_id=382",gWorldManager->getDatabase()->galaxy(),maintenance,this->getId()); this->setCurrentMaintenance(maintenance); } break; } }
NPCObject* NonPersistentNpcFactory::createNonPersistentNpc(DatabaseResult* result, uint64 templateId, uint64 npcNewId, uint32 familyId, uint64 controllingObject) { NPCObject* npc; switch(familyId) { case NpcFamily_Trainer: { npc = new Trainer(); } break; case NpcFamily_Filler: { npc = new FillerNPC(); } break; case NpcFamily_QuestGiver: { npc = new QuestGiver(); } break; case NpcFamily_AttackableObject: { // Stuff like Debris. npc = new AttackableStaticNpc(); } break; case NpcFamily_AttackableCreatures: { // gLogger->logMsgF("NonPersistentNpcFactory::_createNonPersistentNpc() Created a NpcFamily_AttackableCreatures", MSG_NORMAL); // Stuff like npc's and womp rats :). npc = new AttackableCreature(templateId); } break; case NpcFamily_NaturalLairs: { // First time lairs. // gLogger->logMsgF("NonPersistentNpcFactory::createNonPersistentNpc() Created a NpcFamily_NaturalLairs", MSG_NORMAL); //Lairs are not supported here, at least not yet. assert(false && "NonPersistentNpcFactory::createNonPersistent NpcFamily_NaturalLairs Lairs are not supported here yet."); npc = new LairObject(templateId); } break; default: { gLogger->logMsgF("NonPersistentNpcFactory::createNonPersistent unknown Family %u",MSG_HIGH,familyId); assert(false && "NonPersistentNpcFactory::createNonPersistent unknown family"); npc = new NPCObject(); } break; } // Set the new temporarily id. npc->setId(npcNewId); // Register object with WorldManager. gWorldManager->addObject(npc, true); Inventory* npcInventory = new Inventory(); npcInventory->setCapacity(50);//we want to be able to fill something in our inventory npcInventory->setParent(npc); uint64 count = result->getRowCount(); result->GetNextRow(mNonPersistentNpcBinding,(void*)npc); // The template for this creature, in case of a respawn. npc->mNpcTemplateId = templateId; // Should bet fetched from attributes, these will do as defaults. npc->mHam.mHealth.setCurrentHitPoints(500); npc->mHam.mAction.setCurrentHitPoints(500); npc->mHam.mMind.setCurrentHitPoints(500); npc->mHam.calcAllModifiedHitPoints(); // inventory npcInventory->setId(npc->mId + 1); npcInventory->setParentId(npc->mId); npcInventory->setModelString("object/tangible/inventory/shared_creature_inventory.iff"); npcInventory->setName("inventory"); npcInventory->setNameFile("item_n"); npcInventory->setTangibleGroup(TanGroup_Inventory); npcInventory->setTangibleType(TanType_CreatureInventory); npc->mEquipManager.addEquippedObject(CreatureEquipSlot_Inventory,npcInventory); if (npc->getNpcFamily() == NpcFamily_AttackableObject) { // Dynamic spawned pve-enabled "static" creatures like debris. npc->setType(ObjType_Creature); npc->setCreoGroup(CreoGroup_AttackableObject); npc->mTypeOptions = 0x0; // Let's start as non-attackable. // npc->togglePvPStateOn((CreaturePvPStatus)(CreaturePvPStatus_Attackable)); } else if (npc->getNpcFamily() == NpcFamily_NaturalLairs) { //Lairs are not supported here, at least not yet. assert(false && "NonPersistentNpcFactory::createNonPersistent NpcFamily_NaturalLairs Lairs not supported here yet"); // Dynamic spawned pve-enabled "static" creatures like lairs. npc->setType(ObjType_Creature); // This will ensure the use of the single H(am) bar. npc->setCreoGroup(CreoGroup_AttackableObject); npc->mTypeOptions = 0x0; npc->togglePvPStateOn((CreaturePvPStatus)(CreaturePvPStatus_Attackable)); // npc->mHam.mHealth.setCurrentHitPoints(5000); // npc->mHam.mHealth.setMaxHitPoints(5000); // npc->mHam.mHealth.setBaseHitPoints(5000); // npc->mHam.calcAllModifiedHitPoints(); // Let's put some credits in the inventory. // npcInventory->setCredits((gRandom->getRand()%25) + 10); // gLogger->logMsgF("NonPersistentNpcFactory::createNonPersistentNpc() WOW, I'm a lair", MSG_NORMAL); } else if (npc->getNpcFamily() == NpcFamily_AttackableCreatures) { // Dynamic spawned pve-enabled creatures. npc->setType(ObjType_Creature); npc->setCreoGroup(CreoGroup_Creature); npc->mTypeOptions = 0x0; if (gWorldConfig->isTutorial()) { npc->togglePvPStateOn((CreaturePvPStatus)(CreaturePvPStatus_Attackable + CreaturePvPStatus_Aggressive + CreaturePvPStatus_Enemy )); } else { npc->togglePvPStateOn((CreaturePvPStatus)(CreaturePvPStatus_Attackable)); } AttackableCreature* attackableNpc = dynamic_cast<AttackableCreature*>(npc); assert(attackableNpc && "NonPersistentNpcFactory::createNonPersistent unable to cast npc to AttackableCreature instance"); // Fix this later // Also set the owner (lair) who's controlling this creature. attackableNpc->setLairId(controllingObject); Weapon* defaultWeapon = new Weapon(); defaultWeapon->setId(gWorldManager->getRandomNpId()); defaultWeapon->setParentId(npc->mId); defaultWeapon->setModelString("object/weapon/melee/unarmed/shared_unarmed_default_player.iff"); defaultWeapon->setGroup(WeaponGroup_Unarmed); defaultWeapon->setEquipSlotMask(CreatureEquipSlot_Weapon); defaultWeapon->addInternalAttribute("weapon_group","1"); npc->mEquipManager.setDefaultWeapon(defaultWeapon); npc->mEquipManager.equipDefaultWeapon(); // Weapon to use should be gotten from attibutes or whereever we find that kind of info. // This little fellow may need a gun. Weapon* pistol = new Weapon(); pistol->setId(gWorldManager->getRandomNpId()); pistol->setParentId(npc->mId); pistol->setModelString("object/weapon/ranged/pistol/shared_pistol_cdef.iff"); pistol->setGroup(WeaponGroup_Pistol); pistol->setEquipSlotMask(CreatureEquipSlot_Weapon); pistol->addInternalAttribute("weapon_group","32"); attackableNpc->setPrimaryWeapon(pistol); // A saber can be handy, too. Weapon* saber = new Weapon(); saber->setId(gWorldManager->getRandomNpId()); saber->setParentId(npc->mId); saber->setModelString("object/weapon/melee/sword/shared_sword_lightsaber_vader.iff"); saber->setGroup(WeaponGroup_2h); saber->setEquipSlotMask(CreatureEquipSlot_Weapon); saber->addInternalAttribute("weapon_group","4"); attackableNpc->setSecondaryWeapon(saber); if (gWorldConfig->isTutorial()) { attackableNpc->equipPrimaryWeapon(); } else { // attackableNpc->equipSecondaryWeapon(); } // Should be handle by "loot manager" // Let's put some credits in the inventory. npcInventory->setCredits((gRandom->getRand()%25) + 10); } else { npc->mTypeOptions = 0x108; } npc->setLoadState(LoadState_Attributes); // Save default direction, since player can make the npc change heading. // Can't apply this to a dynamically created npc. // npc->storeDefaultDirection(); return npc; }