public MobInter getNearestMobInteract() { MobInter mi = null; uint[] keys = WorldObjects.World.getImportantKeysByPosition(this.Position.Data, 4000); float minDistance = float.MaxValue; foreach (uint key in keys) { if (!sWorld.getWorld(this.vob.Map).MobInterPositionList.ContainsKey(key)) { continue; } List <WorldObjects.Mobs.MobInter> mobs = sWorld.getWorld(this.vob.Map).MobInterPositionList[key]; foreach (WorldObjects.Mobs.MobInter m in mobs) { if (mi == null) { minDistance = (m.Position - this.Position).Length; mi = (MobInter)m.ScriptingVob; continue; } float mD = (m.Position - this.Position).Length; if (mD < minDistance) { mi = (MobInter)m.ScriptingVob; minDistance = mD; } } } return(mi); }
public static Int32 StartInteraction(String message) { int address = Convert.ToInt32(message); Process process = Process.ThisProcess(); try { oCNpc npc = new oCNpc(process, process.ReadInt(address + 4)); if (oCNpc.Player(process).Address == npc.Address) { oCMobInter mobInter = new oCMobInter(process, process.ReadInt(address)); if (!sWorld.SpawnedVobDict.ContainsKey(mobInter.Address)) { return(0); } MobInter mI = (MobInter)sWorld.SpawnedVobDict[mobInter.Address]; BitStream stream = Program.client.sentBitStream; stream.Reset(); stream.Write((byte)RakNet.DefaultMessageIDTypes.ID_USER_PACKET_ENUM); stream.Write((byte)NetworkID.MobInterMessage); stream.Write((byte)MobInterNetwork.StartInteraction); stream.Write(Player.Hero.ID); stream.Write(mI.ID); Program.client.client.Send(stream, PacketPriority.HIGH_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS, true); } } catch (Exception ex) { zERROR.GetZErr(Process.ThisProcess()).Report(2, 'G', ex.ToString(), 0, "hMobInter.cs", 0); } return(0); }
/// <summary> /// Not in use anymore! /// </summary> /// <param name="message"></param> /// <returns></returns> public static Int32 EV_CreateInteractItem(String message) { Process Process = Process.ThisProcess(); try { int address = Convert.ToInt32(message); oCNpc npc = new oCNpc(Process, Process.ReadInt(address)); oCMsgManipulate oDD = new oCMsgManipulate(Process, Process.ReadInt(address + 4)); oCMobInter mobinter = npc.GetInteractMob(); MobInter mobInt = null; if (sWorld.SpawnedVobDict.ContainsKey(mobinter.Address)) { mobInt = (MobInter)sWorld.SpawnedVobDict[mobinter.Address]; oDD.InstanceName.Set("ITGUC_" + mobInt.UseWithItem.ID); zERROR.GetZErr(Process.ThisProcess()).Report(2, 'G', "MobInter-Setted! " + mobInt.UseWithItem.ID, 0, "Program.cs", 0); } else { zERROR.GetZErr(Process.ThisProcess()).Report(2, 'G', "Not founded: MobInter! " + mobinter.Address, 0, "Program.cs", 0); } } catch (Exception ex) { zERROR.GetZErr(Process.ThisProcess()).Report(2, 'G', "Exception: " + ex.Message + " " + ex.StackTrace + " " + ex.Source, 0, "Program.cs", 0); } return(0); }
public void Read(RakNet.BitStream stream, RakNet.Packet packet, Client client) { int vobID = 0, playerID = 0; byte mobInterTypeInt = 0; char mobInterKey = '0'; short startChangeState0 = 0, startChangeState1 = 1; stream.Read(out mobInterTypeInt); stream.Read(out playerID); stream.Read(out vobID); MobInterNetwork mobInterFlags = (MobInterNetwork)mobInterTypeInt; if (mobInterFlags.HasFlag(MobInterNetwork.PickLock)) { stream.Read(out mobInterKey); } if (mobInterFlags.HasFlag(MobInterNetwork.StartStateChange)) { stream.Read(out startChangeState0); stream.Read(out startChangeState1); } if (playerID == 0 || !sWorld.VobDict.ContainsKey(playerID)) { throw new Exception("Player not found!"); } Vob plVob = sWorld.VobDict[playerID]; if (!(plVob is NPCProto)) { throw new Exception("PlayerVob was not from type Player: " + plVob); } NPCProto player = (NPCProto)plVob; if (vobID == 0 || !sWorld.VobDict.ContainsKey(vobID)) { throw new Exception("Vob not found!"); } Vob vob = sWorld.VobDict[vobID]; if (!(vob is MobInter)) { throw new Exception("Vob was not from type MobInter: " + vob); } MobInter mob = (MobInter)vob; Process process = Process.ThisProcess(); if (mobInterFlags == MobInterNetwork.PickLock) { if (!(vob is MobLockable)) { throw new Exception("Vob was not from type MobLockable: " + vob); } } else if (mobInterFlags == MobInterNetwork.OnTrigger) { mob.State = 1; if (mob.Address != 0) { oCMobInter mI = new oCMobInter(process, mob.Address); //mI.GetModel().StartAnimation("T_S0_2_S1"); mI.OnTrigger(new zCVob(process, mI.Address), new zCVob(process, player.Address)); //mI.State = 1; //mI.StateAniID = mI.GetModel().GetAniIDFromAniName("S_S1"); } } else if (mobInterFlags == MobInterNetwork.OnUnTrigger) { mob.State = 0; if (mob.Address != 0) { oCMobInter mI = new oCMobInter(process, mob.Address); //mI.GetModel().StartAnimation("T_S1_2_S0"); mI.OnUnTrigger(new zCVob(process, mI.Address), new zCVob(process, player.Address)); //mI.State = 0; //mI.StateAniID = mI.GetModel().GetAniIDFromAniName("S_S0"); //mI.StateAniID = mI.GetModel(). } } else if (mobInterFlags == MobInterNetwork.StartInteraction) { if (mob.Address != 0) { new oCMobInter(process, mob.Address).StartInteraction(new oCNpc(process, player.Address)); } } else if (mobInterFlags == MobInterNetwork.StopInteraction) { if (mob.Address != 0) { new oCMobInter(process, mob.Address).StopInteraction(new oCNpc(process, player.Address)); } } else if (mobInterFlags == MobInterNetwork.StartStateChange) { if (mob.Address != 0) { oCMobInter mI = new oCMobInter(process, mob.Address); mI.StartStateChange(new oCNpc(process, player.Address), startChangeState0, startChangeState1); } } }
public static void Write(NPCProto proto) { if (proto.Address == 0) { return; } Process process = Process.ThisProcess(); oCNpc npc = new oCNpc(process, proto.Address); if (npc.AniCtrl.Address == 0) { return; } NPCChangedFlags changeFlags = 0; oCItem iArmor = npc.GetEquippedArmor(); Item armor = null; oCItem iWeapon = npc.GetEquippedMeleeWeapon(); Item weapon = null; oCItem iRangeWeapon = npc.GetEquippedRangedWeapon(); Item rangeWeapon = null; Vob focusVobID = null; NPCProto enemyVobID = null; MobInter MobInterID = null; int mobInterAddress = npc.GetInteractMob().Address; if (npc.FocusVob.Address != 0 && sWorld.SpawnedVobDict.ContainsKey(npc.FocusVob.Address)) { focusVobID = sWorld.SpawnedVobDict[npc.FocusVob.Address]; } if (npc.Enemy.Address != 0 && sWorld.SpawnedVobDict.ContainsKey(npc.Enemy.Address)) { enemyVobID = (NPCProto)sWorld.SpawnedVobDict[npc.Enemy.Address]; } if (mobInterAddress != 0 && sWorld.SpawnedVobDict.ContainsKey(mobInterAddress)) { MobInterID = (MobInter)sWorld.SpawnedVobDict[mobInterAddress]; } Item selectedSpell = null; if (npc.MagBook != null && npc.MagBook.Address != 0) { oCItem spellItem = npc.MagBook.GetSpellItem(npc.MagBook.GetSelectedSpellNr()); if (spellItem != null && spellItem.Address != 0) { Vob spellVob = null; sWorld.SpawnedVobDict.TryGetValue(spellItem.Address, out spellVob); selectedSpell = (Item)spellVob; } } if (iArmor.Address != 0) { armor = (Item)sWorld.SpawnedVobDict[iArmor.Address]; } if (iWeapon.Address != 0) { weapon = (Item)sWorld.SpawnedVobDict[iWeapon.Address]; } if (iRangeWeapon.Address != 0) { rangeWeapon = (Item)sWorld.SpawnedVobDict[iRangeWeapon.Address]; } int weaponMode = npc.WeaponMode; Item[] SlotItems = new Item[9]; for (int i = 0; i < SlotItems.Length; i++) { oCItem slItem = npc.GetSlotItem(oCNpc.getSlotString(process, i)); if (slItem.Address != 0 && sWorld.SpawnedVobDict.ContainsKey(slItem.Address)) { SlotItems[i] = (Item)sWorld.SpawnedVobDict[slItem.Address]; } } bool isdead = false; if (npc.IsDead() > 0) { isdead = true; } bool isUnconscious = false; if (npc.IsUnconscious() > 0) { isUnconscious = true; } bool isSwimming = false; if (npc.AniCtrl.GetWalkModeString() == null || npc.AniCtrl.GetWalkModeString().Trim().ToLower().Length == 0) { isSwimming = true; } zString str = npc.GetSectorNameVobIsIn(); String portalRoom = ""; if (str.Address != 0) { portalRoom = str.Value.Trim().ToLower(); } //Setting ChangeFlags: if (proto.Armor != armor) { changeFlags |= NPCChangedFlags.EQUIP_ARMOR; } if (proto.Weapon != weapon) { changeFlags |= NPCChangedFlags.EQUIP_NW; } if (proto.RangeWeapon != rangeWeapon) { changeFlags |= NPCChangedFlags.EQUIP_RW; } if (proto.WeaponMode != weaponMode) { changeFlags |= NPCChangedFlags.WeaponMode; } for (int i = 0; i < SlotItems.Length; i++) { if (proto.Slots[i] != SlotItems[i]) { changeFlags |= (NPCChangedFlags)((int)NPCChangedFlags.SLOT1 << i); } } if (proto.FocusVob != focusVobID) { changeFlags |= NPCChangedFlags.VOBFOCUS; } if (proto.Enemy != enemyVobID) { changeFlags |= NPCChangedFlags.ENEMYFOCUS; } if (proto.MobInter != MobInterID) { changeFlags |= NPCChangedFlags.MOBINTERACT; } if (proto.IsDead != isdead) { changeFlags |= NPCChangedFlags.ISDEAD; } if (proto.IsUnconcious != isUnconscious) { changeFlags |= NPCChangedFlags.ISUNCONSCIOUS; } if (proto.IsSwimming != isSwimming) { changeFlags |= NPCChangedFlags.ISSWIMMING; } if (!proto.PortalRoom.Equals(portalRoom)) { changeFlags |= NPCChangedFlags.PORTALROOM; } if (selectedSpell != proto.ActiveSpell) { changeFlags |= NPCChangedFlags.ACTIVE_SPELL; } if (changeFlags == 0) { return; } //zERROR.GetZErr(Process.ThisProcess()).Report(2, 'G', "ChangeFlags: " + changeFlags, 0, "Client.cs", 0); //Writing Data: BitStream stream = Program.client.sentBitStream; stream.Reset(); stream.Write((byte)RakNet.DefaultMessageIDTypes.ID_USER_PACKET_ENUM); stream.Write((byte)NetworkID.NPCUpdateMessage); stream.Write(proto.ID); stream.Write((int)changeFlags); //Equipment: if (changeFlags.HasFlag(NPCChangedFlags.EQUIP_ARMOR)) { proto.Armor = armor; if (proto.Armor == null) { stream.Write(0); } else { stream.Write(proto.Armor.ID); } } if (changeFlags.HasFlag(NPCChangedFlags.EQUIP_NW)) { proto.Weapon = weapon; if (proto.Weapon == null) { stream.Write(0); } else { stream.Write(proto.Weapon.ID); } } if (changeFlags.HasFlag(NPCChangedFlags.EQUIP_RW)) { proto.RangeWeapon = rangeWeapon; if (proto.RangeWeapon == null) { stream.Write(0); } else { stream.Write(proto.RangeWeapon.ID); } } if (changeFlags.HasFlag(NPCChangedFlags.WeaponMode)) { proto.WeaponMode = weaponMode; stream.Write(weaponMode); } for (int i = 0; i < SlotItems.Length; i++) { if (changeFlags.HasFlag((NPCChangedFlags)((int)NPCChangedFlags.SLOT1 << i))) { proto.Slots[i] = SlotItems[i]; if (SlotItems[i] == null) { stream.Write(0); } else { stream.Write(SlotItems[i].ID); } } } if (changeFlags.HasFlag(NPCChangedFlags.VOBFOCUS)) { proto.FocusVob = focusVobID; if (focusVobID == null) { stream.Write(0); } else { stream.Write(focusVobID.ID); } } if (changeFlags.HasFlag(NPCChangedFlags.ENEMYFOCUS)) { proto.Enemy = enemyVobID; if (enemyVobID == null) { stream.Write(0); } else { stream.Write(enemyVobID.ID); } } if (changeFlags.HasFlag(NPCChangedFlags.MOBINTERACT)) { proto.MobInter = MobInterID; if (MobInterID == null) { stream.Write(0); } else { stream.Write(MobInterID.ID); } } if (changeFlags.HasFlag(NPCChangedFlags.ISDEAD)) { proto.IsDead = isdead; stream.Write(proto.IsDead); } if (changeFlags.HasFlag(NPCChangedFlags.ISUNCONSCIOUS)) { proto.IsUnconcious = isUnconscious; stream.Write(proto.IsUnconcious); } if (changeFlags.HasFlag(NPCChangedFlags.ISSWIMMING)) { proto.IsSwimming = isSwimming; stream.Write(proto.IsSwimming); } if (changeFlags.HasFlag(NPCChangedFlags.PORTALROOM)) { proto.PortalRoom = portalRoom; stream.Write(proto.PortalRoom); } if (changeFlags.HasFlag(NPCChangedFlags.ACTIVE_SPELL)) { proto.ActiveSpell = selectedSpell; if (proto.ActiveSpell == null) { stream.Write(0); } else { stream.Write(proto.ActiveSpell.ID); } } zERROR.GetZErr(Process.ThisProcess()).Report(2, 'G', "Getted ChangeFlags: " + changeFlags, 0, "Client.cs", 0); Program.client.client.Send(stream, PacketPriority.MEDIUM_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS, true); }
public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server) { int vobID = 0, playerID = 0; byte mobInterTypeInt = 0; char mobInterKey = '0'; stream.Read(out mobInterTypeInt); stream.Read(out playerID); stream.Read(out vobID); MobInterNetwork mobInterFlags = (MobInterNetwork)mobInterTypeInt; if (mobInterFlags.HasFlag(MobInterNetwork.PickLock)) { stream.Read(out mobInterKey); } if (playerID == 0 || !sWorld.VobDict.ContainsKey(playerID)) { throw new Exception("Player not found!"); } Vob plVob = sWorld.VobDict[playerID]; if (!(plVob is NPCProto)) { throw new Exception("PlayerVob was not from type Player: " + plVob); } NPCProto player = (NPCProto)plVob; if (vobID == 0 || !sWorld.VobDict.ContainsKey(vobID)) { throw new Exception("Vob not found!"); } Vob vob = sWorld.VobDict[vobID]; if (!(vob is MobInter)) { throw new Exception("Vob was not from type MobInter: " + vob); } stream.ResetReadPointer(); Program.server.ServerInterface.Send(stream, PacketPriority.HIGH_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, packet.guid, true); MobInter mob = (MobInter)vob; if (mobInterFlags == MobInterNetwork.PickLock) { if (!(vob is MobLockable)) { throw new Exception("Vob was not from type MobLockable: " + vob); } MobLockable mobLock = (MobLockable)mob; Scripting.Objects.Mob.MobLockable.OnContainerPickLock((Scripting.Objects.Mob.MobLockable)mobLock.ScriptingVob, player.ScriptingNPC, mobInterKey); } else if (mobInterFlags == MobInterNetwork.OnTrigger) { mob.State = 1; Scripting.Objects.Mob.MobInter.isOnTrigger((Scripting.Objects.Mob.MobInter)mob.ScriptingVob, player.ScriptingNPC); } else if (mobInterFlags == MobInterNetwork.OnUnTrigger) { mob.State = 0; Scripting.Objects.Mob.MobInter.isOnUnTrigger((Scripting.Objects.Mob.MobInter)mob.ScriptingVob, player.ScriptingNPC); } else if (mobInterFlags == MobInterNetwork.StartInteraction) { Scripting.Objects.Mob.MobInter.isOnStartInteraction((Scripting.Objects.Mob.MobInter)mob.ScriptingVob, player.ScriptingNPC); } else if (mobInterFlags == MobInterNetwork.StopInteraction) { Scripting.Objects.Mob.MobInter.isOnStopInteraction((Scripting.Objects.Mob.MobInter)mob.ScriptingVob, player.ScriptingNPC); } }
private void untrigger(MobInter sender, NPCProto npc) { Logger.log(Logger.LOG_INFO, npc.Name + " untriggers " + sender); }
private void stopInteract(MobInter sender, NPCProto npc) { Logger.log(Logger.LOG_INFO, npc.Name + " stop Interaction " + sender); }