コード例 #1
0
ファイル: embparser.cpp プロジェクト: AthrogatePEQ/Server
void PerlembParser::ExportEventVariables(std::string &package_name, QuestEventID event, uint32 objid, const char * data,
        NPC* npcmob, ItemInst* iteminst, Mob* mob, uint32 extradata, std::vector<EQEmu::Any> *extra_pointers)
{
    switch (event) {
    case EVENT_SAY: {
        if(npcmob && mob) {
            npcmob->DoQuestPause(mob);
        }

        ExportVar(package_name.c_str(), "data", objid);
        ExportVar(package_name.c_str(), "text", data);
        ExportVar(package_name.c_str(), "langid", extradata);
        break;
    }

    case EVENT_TRADE: {
        if(extra_pointers) {
            size_t sz = extra_pointers->size();
            for(size_t i = 0; i < sz; ++i) {
                ItemInst *inst = EQEmu::any_cast<ItemInst*>(extra_pointers->at(i));

                std::string var_name = "item";
                var_name += std::to_string(i + 1);

                if(inst) {
                    ExportVar(package_name.c_str(), var_name.c_str(), inst->GetItem()->ID);

                    std::string temp_var_name = var_name;
                    temp_var_name += "_charges";
                    ExportVar(package_name.c_str(), temp_var_name.c_str(), inst->GetCharges());

                    temp_var_name = var_name;
                    temp_var_name += "_attuned";
                    ExportVar(package_name.c_str(), temp_var_name.c_str(), inst->IsAttuned());
                } else {
                    ExportVar(package_name.c_str(), var_name.c_str(), 0);

                    std::string temp_var_name = var_name;
                    temp_var_name += "_charges";
                    ExportVar(package_name.c_str(), temp_var_name.c_str(), 0);

                    temp_var_name = var_name;
                    temp_var_name += "_attuned";
                    ExportVar(package_name.c_str(), temp_var_name.c_str(), 0);
                }
            }
        }

        ExportVar(package_name.c_str(), "copper", GetVar("copper." + std::string(itoa(objid))).c_str());
        ExportVar(package_name.c_str(), "silver", GetVar("silver." + std::string(itoa(objid))).c_str());
        ExportVar(package_name.c_str(), "gold", GetVar("gold." + std::string(itoa(objid))).c_str());
        ExportVar(package_name.c_str(), "platinum", GetVar("platinum." + std::string(itoa(objid))).c_str());
        std::string hashname = package_name + std::string("::itemcount");
        perl->eval(std::string("%").append(hashname).append(" = ();").c_str());
        perl->eval(std::string("++$").append(hashname).append("{$").append(package_name).append("::item1};").c_str());
        perl->eval(std::string("++$").append(hashname).append("{$").append(package_name).append("::item2};").c_str());
        perl->eval(std::string("++$").append(hashname).append("{$").append(package_name).append("::item3};").c_str());
        perl->eval(std::string("++$").append(hashname).append("{$").append(package_name).append("::item4};").c_str());
        break;
    }

    case EVENT_WAYPOINT_ARRIVE:
    case EVENT_WAYPOINT_DEPART: {
        ExportVar(package_name.c_str(), "wp", data);
        break;
    }

    case EVENT_HP: {
        if (extradata == 1) {
            ExportVar(package_name.c_str(), "hpevent", "-1");
            ExportVar(package_name.c_str(), "inchpevent", data);
        }
        else
        {
            ExportVar(package_name.c_str(), "hpevent", data);
            ExportVar(package_name.c_str(), "inchpevent", "-1");
        }
        break;
    }

    case EVENT_TIMER: {
        ExportVar(package_name.c_str(), "timer", data);
        break;
    }

    case EVENT_SIGNAL: {
        ExportVar(package_name.c_str(), "signal", data);
        break;
    }

    case EVENT_NPC_SLAY: {
        ExportVar(package_name.c_str(), "killed", mob->GetNPCTypeID());
        break;
    }

    case EVENT_COMBAT: {
        ExportVar(package_name.c_str(), "combat_state", data);
        break;
    }

    case EVENT_CLICK_DOOR: {
        ExportVar(package_name.c_str(), "doorid", data);
        ExportVar(package_name.c_str(), "version", zone->GetInstanceVersion());
        break;
    }

    case EVENT_LOOT: {
        Seperator sep(data);
        ExportVar(package_name.c_str(), "looted_id", sep.arg[0]);
        ExportVar(package_name.c_str(), "looted_charges", sep.arg[1]);
        ExportVar(package_name.c_str(), "corpse", sep.arg[2]);
        break;
    }

    case EVENT_ZONE: {
        ExportVar(package_name.c_str(), "target_zone_id", data);
        break;
    }

    case EVENT_CAST_ON:
    case EVENT_CAST:
    case EVENT_CAST_BEGIN: {
        ExportVar(package_name.c_str(), "spell_id", data);
        break;
    }

    case EVENT_TASK_ACCEPTED: {
        ExportVar(package_name.c_str(), "task_id", data);
        break;
    }

    case EVENT_TASK_STAGE_COMPLETE: {
        Seperator sep(data);
        ExportVar(package_name.c_str(), "task_id", sep.arg[0]);
        ExportVar(package_name.c_str(), "activity_id", sep.arg[1]);
        break;
    }

    case EVENT_TASK_FAIL: {
        Seperator sep(data);
        ExportVar(package_name.c_str(), "task_id", sep.arg[0]);
        break;
    }

    case EVENT_TASK_COMPLETE:
    case EVENT_TASK_UPDATE: {
        Seperator sep(data);
        ExportVar(package_name.c_str(), "donecount", sep.arg[0]);
        ExportVar(package_name.c_str(), "activity_id", sep.arg[1]);
        ExportVar(package_name.c_str(), "task_id", sep.arg[2]);
        break;
    }

    case EVENT_PLAYER_PICKUP: {
        ExportVar(package_name.c_str(), "picked_up_id", data);
        ExportVar(package_name.c_str(), "picked_up_entity_id", extradata);
        break;
    }

    case EVENT_AGGRO_SAY: {
        ExportVar(package_name.c_str(), "data", objid);
        ExportVar(package_name.c_str(), "text", data);
        ExportVar(package_name.c_str(), "langid", extradata);
        break;
    }

    case EVENT_POPUP_RESPONSE: {
        ExportVar(package_name.c_str(), "popupid", data);
        break;
    }
    case EVENT_ENVIRONMENTAL_DAMAGE: {
        Seperator sep(data);
        ExportVar(package_name.c_str(), "env_damage", sep.arg[0]);
        ExportVar(package_name.c_str(), "env_damage_type", sep.arg[1]);
        ExportVar(package_name.c_str(), "env_final_damage", sep.arg[2]);
        break;
    }

    case EVENT_PROXIMITY_SAY: {
        ExportVar(package_name.c_str(), "data", objid);
        ExportVar(package_name.c_str(), "text", data);
        ExportVar(package_name.c_str(), "langid", extradata);
        break;
    }

    case EVENT_SCALE_CALC:
    case EVENT_ITEM_ENTER_ZONE: {
        // need a valid ItemInst pointer check here..unsure how to cancel this process
        ExportVar(package_name.c_str(), "itemid", objid);
        ExportVar(package_name.c_str(), "itemname", iteminst->GetItem()->Name);
        break;
    }

    case EVENT_ITEM_CLICK_CAST:
    case EVENT_ITEM_CLICK: {
        // need a valid ItemInst pointer check here..unsure how to cancel this process
        ExportVar(package_name.c_str(), "itemid", objid);
        ExportVar(package_name.c_str(), "itemname", iteminst->GetItem()->Name);
        ExportVar(package_name.c_str(), "slotid", extradata);
        ExportVar(package_name.c_str(), "spell_id", iteminst->GetItem()->Click.Effect);
        break;
    }

    case EVENT_GROUP_CHANGE: {
        if(mob && mob->IsClient())
        {
            ExportVar(package_name.c_str(), "grouped", mob->IsGrouped());
            ExportVar(package_name.c_str(), "raided", mob->IsRaidGrouped());
        }
        break;
    }

    case EVENT_HATE_LIST: {
        ExportVar(package_name.c_str(), "hate_state", data);
        break;
    }

    case EVENT_SPELL_EFFECT_CLIENT:
    case EVENT_SPELL_EFFECT_NPC:
    case EVENT_SPELL_BUFF_TIC_CLIENT:
    case EVENT_SPELL_BUFF_TIC_NPC:
    {
        ExportVar(package_name.c_str(), "caster_id", extradata);
        break;
    }

    //tradeskill events
    case EVENT_COMBINE_SUCCESS:
    case EVENT_COMBINE_FAILURE:
    {
        ExportVar(package_name.c_str(), "recipe_id", extradata);
        ExportVar(package_name.c_str(), "recipe_name", data);
        break;
    }

    case EVENT_FORAGE_SUCCESS: {
        ExportVar(package_name.c_str(), "foraged_item", extradata);
        break;
    }

    case EVENT_FISH_SUCCESS: {
        ExportVar(package_name.c_str(), "fished_item", extradata);
        break;
    }

    case EVENT_CLICK_OBJECT: {
        ExportVar(package_name.c_str(), "objectid", data);
        ExportVar(package_name.c_str(), "clicker_id", extradata);
        break;
    }

    case EVENT_DISCOVER_ITEM: {
        ExportVar(package_name.c_str(), "itemid", extradata);
        break;
    }

    case EVENT_COMMAND: {
        ExportVar(package_name.c_str(), "text", data);
        ExportVar(package_name.c_str(), "data", "0");
        ExportVar(package_name.c_str(), "langid", "0");
        break;
    }

    case EVENT_RESPAWN: {
        ExportVar(package_name.c_str(), "option", data);
        ExportVar(package_name.c_str(), "resurrect", extradata);
        break;
    }

    case EVENT_DEATH:
    case EVENT_DEATH_COMPLETE: {
        Seperator sep(data);
        ExportVar(package_name.c_str(), "killer_id", sep.arg[0]);
        ExportVar(package_name.c_str(), "killer_damage", sep.arg[1]);
        ExportVar(package_name.c_str(), "killer_spell", sep.arg[2]);
        ExportVar(package_name.c_str(), "killer_skill", sep.arg[3]);
        break;
    }
    case EVENT_DROP_ITEM: {
        ExportVar(package_name.c_str(), "quantity", iteminst->IsStackable() ? iteminst->GetCharges() : 1);
        ExportVar(package_name.c_str(), "itemname", iteminst->GetItem()->Name);
        ExportVar(package_name.c_str(), "itemid", iteminst->GetItem()->ID);
        ExportVar(package_name.c_str(), "spell_id", iteminst->GetItem()->Click.Effect);
        ExportVar(package_name.c_str(), "slotid", extradata);
        break;
    }
    case EVENT_SPAWN_ZONE: {
        Seperator sep(data);
        ExportVar(package_name.c_str(), "spawned_entity_id", sep.arg[0]);
        ExportVar(package_name.c_str(), "spawned_npc_id", sep.arg[1]);
        break;
    }
    case EVENT_DEATH_ZONE: {
        Seperator sep(data);
        ExportVar(package_name.c_str(), "killer_id", sep.arg[0]);
        ExportVar(package_name.c_str(), "killer_damage", sep.arg[1]);
        ExportVar(package_name.c_str(), "killer_spell", sep.arg[2]);
        ExportVar(package_name.c_str(), "killer_skill", sep.arg[3]);
        ExportVar(package_name.c_str(), "killed_npc_id", sep.arg[4]);
        break;
    }

    default: {
        break;
    }
    }
}
コード例 #2
0
ファイル: tradeskills.cpp プロジェクト: rencro/Server
// Perform tradeskill combine
void Object::HandleCombine(Client* user, const NewCombine_Struct* in_combine, Object *worldo)
{
	if (!user || !in_combine) {
		Log.Out(Logs::General, Logs::Error, "Client or NewCombine_Struct not set in Object::HandleCombine");
		return;
	}

	Inventory& user_inv = user->GetInv();
	PlayerProfile_Struct& user_pp = user->GetPP();
	ItemInst* container = nullptr;
	ItemInst* inst = nullptr;
	uint8 c_type = 0xE8;
	uint32 some_id = 0;
	bool worldcontainer=false;

	if (in_combine->container_slot == legacy::SLOT_TRADESKILL) {
		if(!worldo) {
			user->Message(13, "Error: Server is not aware of the tradeskill container you are attempting to use");
			return;
		}
		c_type = worldo->m_type;
		inst = worldo->m_inst;
		worldcontainer=true;
	}
	else {
		inst = user_inv.GetItem(in_combine->container_slot);
		if (inst) {
			const Item_Struct* item = inst->GetItem();
			if (item && inst->IsType(ItemClassContainer)) {
				c_type = item->BagType;
				some_id = item->ID;
			}
		}
	}

	if (!inst || !inst->IsType(ItemClassContainer)) {
		user->Message(13, "Error: Server does not recognize specified tradeskill container");
		return;
	}

	container = inst;
	if (container->GetItem() && container->GetItem()->BagType == BagTypeTransformationmold) {
		const ItemInst* inst = container->GetItem(0);
		bool AllowAll = RuleB(Inventory, AllowAnyWeaponTransformation);
		if (inst && ItemInst::CanTransform(inst->GetItem(), container->GetItem(), AllowAll)) {
			const Item_Struct* new_weapon = inst->GetItem();
			user->DeleteItemInInventory(Inventory::CalcSlotId(in_combine->container_slot, 0), 0, true);
			container->Clear();
			user->SummonItem(new_weapon->ID, inst->GetCharges(), inst->GetAugmentItemID(0), inst->GetAugmentItemID(1), inst->GetAugmentItemID(2), inst->GetAugmentItemID(3), inst->GetAugmentItemID(4), inst->GetAugmentItemID(5), inst->IsAttuned(), MainCursor, container->GetItem()->Icon, atoi(container->GetItem()->IDFile + 2));
			user->Message_StringID(4, TRANSFORM_COMPLETE, inst->GetItem()->Name);
			if (RuleB(Inventory, DeleteTransformationMold))
				user->DeleteItemInInventory(in_combine->container_slot, 0, true);
		}
		else if (inst) {
			user->Message_StringID(4, TRANSFORM_FAILED, inst->GetItem()->Name);
		}
		EQApplicationPacket* outapp = new EQApplicationPacket(OP_TradeSkillCombine, 0);
		user->QueuePacket(outapp);
		safe_delete(outapp);
		return;
	}

	if (container->GetItem() && container->GetItem()->BagType == BagTypeDetransformationmold) {
		const ItemInst* inst = container->GetItem(0);
		if (inst && inst->GetOrnamentationIcon() && inst->GetOrnamentationIcon()) {
			const Item_Struct* new_weapon = inst->GetItem();
			user->DeleteItemInInventory(Inventory::CalcSlotId(in_combine->container_slot, 0), 0, true);
			container->Clear();
			user->SummonItem(new_weapon->ID, inst->GetCharges(), inst->GetAugmentItemID(0), inst->GetAugmentItemID(1), inst->GetAugmentItemID(2), inst->GetAugmentItemID(3), inst->GetAugmentItemID(4), inst->GetAugmentItemID(5), inst->IsAttuned(), MainCursor, 0, 0);
			user->Message_StringID(4, TRANSFORM_COMPLETE, inst->GetItem()->Name);
		}
		else if (inst) {
			user->Message_StringID(4, DETRANSFORM_FAILED, inst->GetItem()->Name);
		}
		EQApplicationPacket* outapp = new EQApplicationPacket(OP_TradeSkillCombine, 0);
		user->QueuePacket(outapp);
		safe_delete(outapp);
		return;
	}

	DBTradeskillRecipe_Struct spec;
	if (!database.GetTradeRecipe(container, c_type, some_id, user->CharacterID(), &spec)) {
		user->Message_StringID(MT_Emote,TRADESKILL_NOCOMBINE);
		EQApplicationPacket* outapp = new EQApplicationPacket(OP_TradeSkillCombine, 0);
		user->QueuePacket(outapp);
		safe_delete(outapp);
		return;
	}

	// Character hasn't learnt the recipe yet.
	// must_learn:
	// bit 1 (0x01): recipe can't be experimented
	// bit 2 (0x02): can try to experiment but not useable for auto-combine until learnt
	// bit 5 (0x10): no learn message, use unlisted flag to prevent it showing up on search
	// bit 6 (0x20): unlisted recipe flag
	if ((spec.must_learn&0xF) == 1 && !spec.has_learnt) {
		// Made up message for the client. Just giving a DNC is the other option.
		user->Message(4, "You need to learn how to combine these first.");
		EQApplicationPacket* outapp = new EQApplicationPacket(OP_TradeSkillCombine, 0);
		user->QueuePacket(outapp);
		safe_delete(outapp);
		return;
	}
	// Character does not have the required skill.
	if(spec.skill_needed > 0 && user->GetSkill(spec.tradeskill) < spec.skill_needed ) {
		// Notify client.
		user->Message(4, "You are not skilled enough.");
		EQApplicationPacket* outapp = new EQApplicationPacket(OP_TradeSkillCombine, 0);
		user->QueuePacket(outapp);
		safe_delete(outapp);
		return;
	}

	//changing from a switch to string of if's since we don't need to iterate through all of the skills in the SkillType enum
	if (spec.tradeskill == SkillAlchemy) {
		if (user_pp.class_ != SHAMAN) {
			user->Message(13, "This tradeskill can only be performed by a shaman.");
			return;
		}
		else if (user_pp.level < MIN_LEVEL_ALCHEMY) {
			user->Message(13, "You cannot perform alchemy until you reach level %i.", MIN_LEVEL_ALCHEMY);
			return;
		}
	}
	else if (spec.tradeskill == SkillTinkering) {
		if (user_pp.race != GNOME) {
			user->Message(13, "Only gnomes can tinker.");
			return;
		}
	}
	else if (spec.tradeskill == SkillMakePoison) {
		if (user_pp.class_ != ROGUE) {
			user->Message(13, "Only rogues can mix poisons.");
			return;
		}
	}

	// Send acknowledgement packets to client
	EQApplicationPacket* outapp = new EQApplicationPacket(OP_TradeSkillCombine, 0);
	user->QueuePacket(outapp);
	safe_delete(outapp);

	//now clean out the containers.
	if(worldcontainer){
		container->Clear();
		outapp = new EQApplicationPacket(OP_ClearObject, sizeof(ClearObject_Struct));
		ClearObject_Struct *cos = (ClearObject_Struct *)outapp->pBuffer;
		cos->Clear = 1;
		user->QueuePacket(outapp);
		safe_delete(outapp);
		database.DeleteWorldContainer(worldo->m_id, zone->GetZoneID());
	} else{
		for (uint8 i = MAIN_BEGIN; i < EmuConstants::MAP_WORLD_SIZE; i++) {
			const ItemInst* inst = container->GetItem(i);
			if (inst) {
				user->DeleteItemInInventory(Inventory::CalcSlotId(in_combine->container_slot,i),0,true);
			}
		}
		container->Clear();
	}
	//do the check and send results...
	bool success = user->TradeskillExecute(&spec);

	// Learn new recipe message
	// Update Made count
	if (success) {
		if (!spec.has_learnt && ((spec.must_learn&0x10) != 0x10)) {
			user->Message_StringID(4, TRADESKILL_LEARN_RECIPE, spec.name.c_str());
		}
		database.UpdateRecipeMadecount(spec.recipe_id, user->CharacterID(), spec.madecount+1);
	}

	// Replace the container on success if required.
	//

	if(success && spec.replace_container) {
		if(worldcontainer){
			//should report this error, but we dont have the recipe ID, so its not very useful
			Log.Out(Logs::General, Logs::Error, "Replace container combine executed in a world container.");
		}
		else
			user->DeleteItemInInventory(in_combine->container_slot, 0, true);
	}
	if (success)
		parse->EventPlayer(EVENT_COMBINE_SUCCESS, user, spec.name.c_str(), spec.recipe_id);
	else
		parse->EventPlayer(EVENT_COMBINE_FAILURE, user, spec.name.c_str(), spec.recipe_id);
}