Beispiel #1
0
void Food::prepareCustomRadialMenu(CreatureObject* creatureObject, uint8 itemCount)
{
    RadialMenu* radial	= new RadialMenu();

    CreatureObject* unknownCreature;
    Inventory* creatureInventory;
    if (this->getParentId() &&
            (unknownCreature = dynamic_cast<CreatureObject*>(gWorldManager->getObjectById(this->getParentId() - 1))) &&
            (creatureInventory = dynamic_cast<Inventory*>(unknownCreature->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory))) &&
            (creatureInventory->getId() == this->getParentId()))
    {
        // Its an object in an inventory

        NPCObject* npcObject = dynamic_cast<NPCObject*>(unknownCreature);
        if (npcObject)
        {
            if ((npcObject->getNpcFamily() == NpcFamily_AttackableCreatures) && npcObject->isDead())
            {
                // I'm pretty sure we are a loot item.
                radial->addItem(1,0,radId_itemPickup,radAction_ObjCallback,"@ui_radial:loot");
                radial->addItem(2,0,radId_examine,radAction_Default);
                mRadialMenu = RadialMenuPtr(radial);
                return;
            }
        }
    }

    // Note: If we are to never use the default "Eat", THEN remove the isTutorial()-condition test.
    if (gWorldConfig->isTutorial())
    {
        // Tutorial clearly states that we shall use the "Use"-option.
        radial->addItem(1,0,radId_itemUse,radAction_ObjCallback,"Use");
    }
    else
    {
        radial->addItem(1,0,radId_itemUse,radAction_ObjCallback,"");		// Default.
    }
    radial->addItem(2,0,radId_examine,radAction_ObjCallback,"");
    radial->addItem(3,0,radId_itemDestroy,radAction_ObjCallback,"");
    mRadialMenu = RadialMenuPtr(radial);


}
MissionObject* MissionManager::generateCraftingMission(MissionObject* mission)
{
	mission->setMissionType(crafting);

	//TEMP!
	string targets[8][2] =
	{
		{"@item_n:output_governor","object/tangible/mission/quest_item/shared_attunement_grid.iff"},
		{"@item_n:current_alternator","object/tangible/mission/quest_item/shared_current_alternator.iff"},
		{"@item_n:nym_hard_drive","object/tangible/loot/quest/shared_nym_hard_drive.iff"},
		{"@item_n:hyperdrive_part_s01","object/tangible/loot/misc/shared_hyperdrive_part_s01.iff"},
		{"@item_n:dermal_analyzer","object/tangible/loot/npc_loot/shared_dermal_analyzer_generic.iff"},
		{"@item_n:feedback_controller","object/tangible/mission/quest_item/shared_feedback_controller.iff"},
		{"@item_n:power_regulator","object/tangible/mission/quest_item/shared_power_regulator.iff"},
		{"@item_n:attunement_grid","object/tangible/mission/quest_item/shared_attunement_grid.iff"}
	};

	int target_num = gRandom->getRand() % 8;

	//END TEMP

	//Randomly choose a crafting mission
	int mission_num = (gRandom->getRand() % 50)+1;
	mission->setNum(mission_num);

	//Creator
	mission->setCreator(creators[gRandom->getRand() % 9]);

	//Title
	sprintf(mt,"m%dt",mission_num);
	mission->setTitleFile("mission/mission_npc_crafting_neutral_easy");
	mission->setTitle(mt);

	//Details
	sprintf(md,"m%dd",mission_num);
	mission->setDetailFile("mission/mission_npc_crafting_neutral_easy");
	mission->setDetail(md);

    //END TEMP

	ObjectSet inRangeNPCs;
	gWorldManager->getSI()->getObjectsInRange(mission->getOwner(),&inRangeNPCs,ObjType_NPC,1500);

	uint32 cntLoop = 0;
	//Start & End
	bool found = false;
	Location mission_start;
    Location mission_dest;
	ObjectSet::iterator it = inRangeNPCs.begin();
	while(!found && !inRangeNPCs.empty())
	{
		cntLoop++;
		++it;

		if(it == inRangeNPCs.end())
			it = inRangeNPCs.begin();

		NPCObject* npc = dynamic_cast<NPCObject*>(*it);
		if(npc->getNpcFamily() == NpcFamily_Filler)
		{
			uint32 roll		= (gRandom->getRand() / (RAND_MAX  + 1ul) * (9 - 1) + 1);
			if((roll = 5)||(cntLoop > inRangeNPCs.size()))
			{
				if(mission_dest.Coordinates.x == 0)
				{
					mission->setDestinationNPC(npc);
					mission_dest.Coordinates = npc->mPosition;
					mission_dest.CellID = 0;
					mission_dest.PlanetCRC = BString(gWorldManager->getPlanetNameThis()).getCrc();
					mission->setDestination(mission_dest);
				}
				else if(mission_start.Coordinates.x == 0 && mission->getDestinationNPC() != npc)
				{
					mission->setStartNPC(npc);
					mission_start.Coordinates = npc->mPosition;
					mission_start.CellID = 0;
					mission_start.PlanetCRC = BString(gWorldManager->getPlanetNameThis()).getCrc();
					mission->setStart(mission_start);
				}
				else
				{
					found = true;
				}
			}
		}
	}

   //Difficulty
	mission->setDifficulty((gRandom->getRand() % 41) + 40); //value from 30 - 80

	//Reward
	mission->setReward(mission->getDifficulty() * ((gRandom->getRand() % 14) + 15)); //Difficulty * rand: 15-28

	//Target
	mission->setTarget((targets[target_num][0]).getRawData()); //will need to be located from the db

	//Mission Target
	mission->setTargetModel((targets[target_num][1]).getCrc()); //crc = object/tangible/mission/quest_item/shared_attunement_grid.iff

return mission;
}
MissionObject* MissionManager::generateEntertainerMission(MissionObject* mission,int count)
{

	count < 5 ?
		mission->setMissionType(musician):
	    mission->setMissionType(dancer);

	//Randomly choose an entertainer mission
	int mission_num = (gRandom->getRand() % 50)+1;
	mission->setNum(mission_num);

	ObjectSet inRangeNPCs;
	gWorldManager->getSI()->getObjectsInRange(mission->getOwner(),&inRangeNPCs,ObjType_NPC,3000);
	//Start
	uint32 cntLoop = 0;
	bool found = false;
	Location mission_dest;
	ObjectSet::iterator it = inRangeNPCs.begin();
	while(!found && !inRangeNPCs.empty())
	{
		cntLoop++;
		++it;
		if(it == inRangeNPCs.end())
			it = inRangeNPCs.begin();

		NPCObject* npc = dynamic_cast<NPCObject*>(*it);
		if(npc->getNpcFamily() == NpcFamily_Filler)
		{
			uint32 roll		= (gRandom->getRand() / (RAND_MAX  + 1ul) * (9 - 1) + 1);
			if((roll = 5)||(cntLoop > inRangeNPCs.size()))
			{
				if(mission_dest.Coordinates.x == 0 && mission->getDestinationNPC() != npc)
				{
					mission->setStartNPC(npc);
					mission_dest.Coordinates = npc->mPosition;
					mission_dest.CellID = 0;
					mission_dest.PlanetCRC = BString(gWorldManager->getPlanetNameThis()).getCrc();
					mission->setDestination(mission_dest);
					mission->setDestinationNPC(npc);
					found = true;
				}
			}
		}
	}

	//Creator
	mission->setCreator(creators[gRandom->getRand() % 9]);

    //Mission Title
	sprintf(mt,"m%dt",mission_num);

	count < 5 ?
		mission->setTitleFile("mission/mission_npc_musician_neutral_easy") :
		mission->setTitleFile("mission/mission_npc_dancer_neutral_easy");
	mission->setTitle(mt);

	//Mission Description
	sprintf(md,"m%do",mission_num);

	count < 5 ?
		mission->setDetailFile("mission/mission_npc_musician_neutral_easy") :
		mission->setDetailFile("mission/mission_npc_dancer_neutral_easy");
	mission->setDetail(md);

   //Diffaculty
	mission->setDifficulty((gRandom->getRand() % 90)+3);

	//Payment
	mission->setReward((gRandom->getRand() % 2500)+500);

	//Target Name
	mission->setTarget("Entertainer");

	//Mission Target
	mission->setTargetModel(0x491099A6); //crc = object/tangible/instrument/shared_organ_max_rebo.iff

return mission;
}
MissionObject* MissionManager::generateDeliverMission(MissionObject* mission)
{
	mission->setMissionType(deliver);

	//TEMP

	missionData mission_deliver_hard[2] =
	{
		{"mission/mission_deliver_neutral_hard",25},
		{"mission/mission_deliver_neutral_hard_non_persistent_from_npc",15},
	};

	//Randomly choose a stf file
	int stf_file = gRandom->getRand() % 2;

	//Randomly choose a mission in that file
	int mission_num = (gRandom->getRand() % mission_deliver_hard[stf_file].num)+1;
	mission->setNum(mission_num);

    //END TEMP

	ObjectSet inRangeNPCs;
	gWorldManager->getSI()->getObjectsInRange(mission->getOwner(),&inRangeNPCs,ObjType_NPC,1500);

	//Start & End
	bool found = false;
	Location mission_start;
    Location mission_dest;
	ObjectSet::iterator it = inRangeNPCs.begin();

	//we may stall the main thread with the way it was done ???? however often enough the mission generation never finished!!!!!!!!!!!!!!!


	//get a list containing all suitable npcs and generate a random number corresponding to one of the npcs

	if(inRangeNPCs.size() < 2)
		return NULL;


	uint32 count = 0;

	while(!found && !inRangeNPCs.empty())
	{
		count ++;
		++it;
		if(it == inRangeNPCs.end())
			it = inRangeNPCs.begin();

		NPCObject* npc = dynamic_cast<NPCObject*>(*it);
		if(npc->getNpcFamily() == NpcFamily_Filler)
		{
			uint32 roll		= (gRandom->getRand() / (RAND_MAX  + 1ul) * (9 - 1) + 1);
			if((roll = 5)||(count > inRangeNPCs.size()))
			{
				if(mission_dest.Coordinates.x == 0)
				{
					mission->setDestinationNPC(npc);
					mission_dest.Coordinates = npc->mPosition;
					mission_dest.CellID = 0;
					mission_dest.PlanetCRC = BString(gWorldManager->getPlanetNameThis()).getCrc();
					mission->setDestination(mission_dest);
				}
				else if(mission_start.Coordinates.x == 0 && mission->getDestinationNPC() != npc)
				{
					mission->setStartNPC(npc);
					mission_start.Coordinates = npc->mPosition;
					mission_start.CellID = 0;
					mission_start.PlanetCRC = BString(gWorldManager->getPlanetNameThis()).getCrc();
					mission->setStart(mission_start);
					found = true;
				}

			}
		}
	}

	//Creator
	mission->setCreator(creators[gRandom->getRand() % 9]);

    //Mission Title
	sprintf(mt,"m%dt",mission_num);

	mission->setTitleFile(mission_deliver_hard[stf_file].mSTF);
	mission->setTitle(mt);

	//Mission Description
	sprintf(md,"m%dd",mission_num);

	mission->setDetailFile(mission_deliver_hard[stf_file].mSTF);
	mission->setDetail(md);

   //Diffaculty
	mission->setDifficulty((gRandom->getRand() % 10)+3);

	//Payment
	mission->setReward((gRandom->getRand() % 300)+50);

	//Mission Target
	mission->setTargetModel(0xE191DBAB); //crc = object/tangible/mission/shared_mission_datadisk.iff

return mission;
}
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;
}