示例#1
0
void InstanceScriptPlayer::RunImplementationCommands(int opcode)
{
	ScriptCore::OpData *instr = &def->instr[curInst];
	switch(opcode)
	{
	case OP_DESPAWN_ALL:
	{
		while(true) {
			CreatureInstance *source = actInst->GetNPCInstanceByCDefID(GetVarValue(instr->param1));
			if(source == NULL)
				break;
			else {
				g_Log.AddMessageFormat("Despawn: %d (%d)", GetVarValue(instr->param1), source->CreatureID);
				actInst->spawnsys.Despawn(source->CreatureID);
			}
		}
		break;
	}
	case OP_DESPAWN:
	{
		CreatureInstance *source = actInst->GetInstanceByCID(GetVarValue(instr->param1));
		g_Log.AddMessageFormat("Despawn: %d (%d)", GetVarValue(instr->param1), source->CreatureDefID);
		if(source == NULL)
			g_Log.AddMessageFormat("Despawn failed, %d does not exist.", GetVarValue(instr->param1));
		else
			actInst->spawnsys.Despawn(GetVarValue(instr->param1));
		break;
	}
	case OP_SPAWN:
		actInst->spawnsys.TriggerSpawn(instr->param1, 0, 0);
		//g_Log.AddMessageFormat("Fired spawn: %d", def->instr[curInst].param1);
		break;
	case OP_SPAWNAT:
		actInst->spawnsys.TriggerSpawn(instr->param1, instr->param2, 0);
		//g_Log.AddMessageFormat("Fired spawn: %d, creature: %d", def->instr[curInst].param1, def->instr[curInst].param2);
		break;
	case OP_SPAWNFLAG:
		actInst->spawnsys.TriggerSpawn(instr->param1, instr->param2, instr->param3);
		//g_Log.AddMessageFormat("Fired spawn: %d, creature: %d", def->instr[curInst].param1, def->instr[curInst].param2);
		break;
	case OP_SPAWNLOC:
		{
			//Pop in reverse order
			int x = PopVarStack();
			int y = PopVarStack();
			int z = PopVarStack();
			if(x != 0 && y != 0 && z != 0)
				actInst->SpawnGeneric(instr->param1, x, y, z, 0);
		}
		break;
	case OP_COUNTALIVE:
		vars[instr->param2] = actInst->CountAlive(instr->param1);
		break;
	case OP_GETNPCID:
		{
			int creatureID = 0;
			CreatureInstance *search = actInst->GetNPCInstanceByCDefID(instr->param1);
			if(search != NULL)
				creatureID = search->CreatureID;
			vars[instr->param2] = creatureID;
		}
		break;
	case OP_SETTARGET:
		{
			CreatureInstance *source = actInst->GetInstanceByCID(GetVarValue(instr->param1));
			CreatureInstance *target = actInst->GetInstanceByCID(GetVarValue(instr->param2));
			if(source != NULL && target != NULL)
				source->SelectTarget(target);
		}
		break;

	case OP_SCAN_NPC_CID:
		{
			InstanceLocation *loc = GetLocationByName(GetStringPtr(instr->param1));
			int index = VerifyIntArrayIndex(instr->param2);
			if(index >= 0)
				ScanNPCCID(loc, intArray[index].arrayData);
		}
		break;
	case OP_SCAN_NPC_CID_FOR:
		{
			InstanceLocation *loc = GetLocationByName(GetStringPtr(instr->param1));
			int index = VerifyIntArrayIndex(instr->param2);
			if(index >= 0)
				ScanNPCCIDFor(loc, instr->param3, intArray[index].arrayData);
		}
		break;
	case OP_GET_CDEF:
		{
			int cdef = 0;
			CreatureInstance *ci = GetNPCPtr(GetVarValue(instr->param1));
			if(ci)
				cdef = ci->CreatureDefID;
			SetVar(instr->param2, cdef);
		}
		break;
	case OP_GET_HEALTH_PERCENT:
		{
			CreatureInstance *ci = GetNPCPtr(GetVarValue(instr->param1));
			int health = 0;
			if(ci)
				health = static_cast<int>(ci->GetHealthRatio() * 100.0F);
			SetVar(instr->param2, health);
		}
		break;
	case OP_ORDER_WALK:
		{
			CreatureInstance *ci = GetNPCPtr(GetVarValue(instr->param1));
			if(ci)
			{
				ci->SetServerFlag(ServerFlags::ScriptMovement, true);
				ci->previousPathNode = 0;   //Disable any path links.
				ci->nextPathNode = 0;
				ci->tetherNodeX = instr->param2;
				ci->tetherNodeZ = instr->param3;
				ci->CurrentTarget.DesLocX = instr->param2;
				ci->CurrentTarget.DesLocZ = instr->param3;
				ci->CurrentTarget.desiredRange = 30;
				ci->Speed = 20;
			}
		}
		break;
	case OP_GET_TARGET:
		{
			int targetID = 0;
			CreatureInstance *ci = GetNPCPtr(GetVarValue(instr->param1));
			if(ci)
			{
				if(ci->CurrentTarget.targ != NULL)
					targetID = ci->CurrentTarget.targ->CreatureID;
			}
			SetVar(instr->param2, targetID);
		}
		break;
	case OP_AI_SCRIPT_JUMP:
		{
			CreatureInstance *ci = GetNPCPtr(GetVarValue(instr->param1));
			if(ci)
			{
				if(ci->aiScript)
					ci->aiScript->JumpToLabel(GetStringPtr(instr->param2));
			}
		}
		break;
	case OP_INFO:
		{
			char buffer[4096];
			int wpos = PrepExt_SendInfoMessage(buffer, GetStringPtr(instr->param1), INFOMSG_INFO);
			actInst->LSendToAllSimulator(buffer, wpos, -1);
		}
		break;
	case OP_CHAT:
		{
			char buffer[4096];
			int wpos = PrepExt_GenericChatMessage(buffer, 0, GetStringPtr(instr->param1), GetStringPtr(instr->param2), GetStringPtr(instr->param3));
			actInst->LSendToAllSimulator(buffer, wpos, -1);
		}
		break;
	case OP_BROADCAST:
		{
			char buffer[4096];
			if(actInst->mZoneDefPtr->mGrove)
			{
				int wpos = PrepExt_SendInfoMessage(buffer, GetStringPtr(instr->param1), INFOMSG_INFO);
				actInst->LSendToAllSimulator(buffer, wpos, -1);
			}
			else
			{
				int wpos = PrepExt_Broadcast(buffer, GetStringPtr(instr->param1));
				actInst->LSendToAllSimulator(buffer, wpos, -1);
			}
		}
		break;
	default:
		g_Log.AddMessageFormat("Unidentified InstanceScriptPlayer OpCode: %d", instr->opCode);
		break;
	}
}
示例#2
0
void QuestScriptPlayer::RunImplementationCommands(int opcode)
{
	ScriptCore::OpData *instr = &def->instr[curInst];
	switch(instr->opCode)
	{
	case OP_INFO:
		{
		char Buffer[1024];
		int size = PrepExt_SendInfoMessage(Buffer, def->stringList[instr->param1].c_str(), INFOMSG_INFO);
		simCall->AttemptSend(Buffer, size);
		}
		break;
	case OP_EFFECT:
		{
		char Buffer[1024];
		int size = PrepExt_SendEffect(Buffer, targetID, def->stringList[instr->param1].c_str(), 0);
		actInst->LSendToAllSimulator(Buffer, size, -1);
		}
		break;
	case OP_WAITFINISH:
		if(!(RunFlags & FLAG_FINISHED))
			advance = 0;
		break;
	case OP_NPCUNUSABLE:
		CreatureInstance *targ;
		targ = actInst->GetNPCInstanceByCID(targetID);
		if(targ != NULL)
		{
			targ->SetServerFlag(ServerFlags::IsUnusable, true);
			//Trigger for deletion
			if(def->instr[curInst].param1 != 0)
			{
				//targ->_AddStatusList(StatusEffects::DEAD, -1);
				targ->SetServerFlag(ServerFlags::TriggerDelete, true);
				targ->deathTime = g_ServerTime + def->instr[curInst].param1;
			}
		}
		break;
	case OP_NPCREMOVE:
		actInst->RemoveNPCInstance(targetID);
		break;
	case OP_REQUIRECDEF:
		if(targetCDef != instr->param1)
			active = false;
		break;
	case OP_SPAWN:
		actInst->spawnsys.TriggerSpawn(instr->param1, 0, 0);
		break;
	case OP_SPAWNAT:
		actInst->SpawnAtProp(instr->param1, instr->param2, RunTimeVar[0], RunTimeVar[1]);
		break;
	case OP_WARPZONE:
		simCall->MainCallSetZone(instr->param1, 0, true);
		break;
	case OP_JMPCDEF:
		if(targetCDef == instr->param1)
		{
			curInst = instr->param2;
			advance = 0;
		}
		break;
	case OP_SETVAR:
		int index;
		index = Util::ClipInt(instr->param1, 0, MAX_VAR - 1);
		RunTimeVar[index] = instr->param2;
		break;
	case OP_EMOTE:
		{
		char Buffer[1024];
		int size = PrepExt_GenericChatMessage(Buffer, sourceID, "", "emote", def->stringList[instr->param1].c_str());
		actInst->LSendToAllSimulator(Buffer, size, -1);
		}
		break;
	default:
		g_Log.AddMessageFormat("Unidentified op type: %d", instr->opCode);
		break;
	}
}