private void listView_items_data_DoubleClick(object sender, EventArgs e) { if (listView_items_data.SelectedIndices.Count > 0) { //action to this item uint id = Util.GetUInt32(listView_items_data.Items[listView_items_data.SelectedIndices[0]].SubItems[2].Text); if (Globals.ItemLock.TryEnterReadLock(Globals.THREAD_WAIT_GUI)) { try { ItemInfo item = Util.GetItem(id); if (item != null) { ServerPackets.ClickItem(id, Util.Float_Int32(item.X), Util.Float_Int32(item.Y), Util.Float_Int32(item.Z), Globals.gamedata.Shift); } } finally { Globals.ItemLock.ExitReadLock(); } } } }
private void UpdateItemsListInternal() { System.Collections.ArrayList dirty_items = new System.Collections.ArrayList(); for (int i = 0; i < listView_items_data_items.Count; i++) { uint id = Util.GetUInt32(((ListViewItem)listView_items_data_items[i]).SubItems[2].Text); if (Globals.gamedata.nearby_items.ContainsKey(id)) { ItemInfo item = Util.GetItem(id); item.InList = true; //update it //((ListViewItem)listView_items_data_items[i]).SubItems[0].Text = Util.GetItemName(item.ItemID); //((ListViewItem)listView_items_data_items[i]).SubItems[1].Text = item.Count.ToString(); //((ListViewItem)listView_items_data_items[i]).SubItems[2].Text = item.ID.ToString(); } else { dirty_items.Add(i); } } //need to remove all dirty items now for (int i = dirty_items.Count - 1; i >= 0; i--) { listView_items_data_items.RemoveAt((int)dirty_items[i]); } dirty_items.Clear(); foreach (ItemInfo item in Globals.gamedata.nearby_items.Values) { if (!item.InList) { item.InList = true; string mesh_info = ""; if (!item.HasMesh) { mesh_info = " [NO MESH]"; } //add it System.Windows.Forms.ListViewItem ObjListItem; ObjListItem = new ListViewItem(Util.GetItemName(item.ItemID) + mesh_info); //ItmID ObjListItem.SubItems.Add(item.Count.ToString()); //Count ObjListItem.SubItems.Add(item.ID.ToString()); //ObjID ObjListItem.ImageIndex = AddInfo.Get_Item_Image_Index(item.ItemID); listView_items_data_items.Add(ObjListItem); } } }
private void listView_items_data_SelectedIndexChanged(object sender, EventArgs e) { string text = ""; if (listView_items_data.SelectedIndices.Count > 0) { //action to this item uint id = Util.GetUInt32(listView_items_data.Items[listView_items_data.SelectedIndices[0]].SubItems[2].Text); ItemInfo item = null; if (Globals.ItemLock.TryEnterReadLock(Globals.THREAD_WAIT_GUI)) { try { item = Util.GetItem(id); } finally { Globals.ItemLock.ExitReadLock(); } } if (item != null) { text = Util.GetItemName(item.ItemID) + Environment.NewLine + item.Count.ToString() + Environment.NewLine + (item.Stackable == 0x01 ? "Stacks" : "Single") + Environment.NewLine + "X: " + item.X.ToString() + Environment.NewLine + "Y: " + item.Y.ToString() + Environment.NewLine + "Z: " + item.Z.ToString() + Environment.NewLine + "Dist: " + Util.Distance(Globals.gamedata.my_char.X, Globals.gamedata.my_char.Y, Globals.gamedata.my_char.Z, item.X, item.Y, item.Z).ToString() + Environment.NewLine + "Type ID: " + item.ItemID + Environment.NewLine + "Unique ID: " + item.ID; } } toolTip1.SetToolTip(listView_items_data, text); }
private static void AnimateStuff() { bool found = false; float vx, vy, vz; float vxx; float movespeed; float time; ////////////////////////////////Animate self try { if (Globals.gamedata.my_char.Moving == true) { if (Globals.gamedata.OOG && ((System.TimeSpan)(System.DateTime.Now - Globals.gamedata.my_char.lastVerifyTime)).Milliseconds > 1000) { //send the verify pos packet ServerPackets.Send_Verify(); } if (Globals.gamedata.my_char.MoveTarget != 0) { found = false; //need to set the dest switch (Globals.gamedata.my_char.MoveTargetType) { case TargetType.ERROR: case TargetType.NONE: //shouldn't get this ever //Globals.l2net_home.Add_OnlyDebug("MoveToPawn MoveTargetType invalid - char: " + Globals.gamedata.my_char.Name + ":" + Globals.gamedata.my_char.ID.ToString() + "--: " + Globals.gamedata.my_char.MoveTarget.ToString()); break; case TargetType.SELF: //shouldn't get this ever... Globals.gamedata.my_char.Dest_X = Globals.gamedata.my_char.X; Globals.gamedata.my_char.Dest_Y = Globals.gamedata.my_char.Y; Globals.gamedata.my_char.Dest_Z = Globals.gamedata.my_char.Z; found = true; break; case TargetType.MYPET: Globals.gamedata.my_char.Dest_X = Globals.gamedata.my_pet.X; Globals.gamedata.my_char.Dest_Y = Globals.gamedata.my_pet.Y; Globals.gamedata.my_char.Dest_Z = Globals.gamedata.my_pet.Z; found = true; break; case TargetType.MYPET1: Globals.gamedata.my_char.Dest_X = Globals.gamedata.my_pet1.X; Globals.gamedata.my_char.Dest_Y = Globals.gamedata.my_pet1.Y; Globals.gamedata.my_char.Dest_Z = Globals.gamedata.my_pet1.Z; found = true; break; case TargetType.MYPET2: Globals.gamedata.my_char.Dest_X = Globals.gamedata.my_pet2.X; Globals.gamedata.my_char.Dest_Y = Globals.gamedata.my_pet2.Y; Globals.gamedata.my_char.Dest_Z = Globals.gamedata.my_pet2.Z; found = true; break; case TargetType.MYPET3: Globals.gamedata.my_char.Dest_X = Globals.gamedata.my_pet3.X; Globals.gamedata.my_char.Dest_Y = Globals.gamedata.my_pet3.Y; Globals.gamedata.my_char.Dest_Z = Globals.gamedata.my_pet3.Z; found = true; break; case TargetType.PLAYER: CharInfo player_target = null; Globals.PlayerLock.EnterReadLock(); try { player_target = Util.GetChar(Globals.gamedata.my_char.MoveTarget); } finally { Globals.PlayerLock.ExitReadLock(); } if (player_target != null) { Globals.gamedata.my_char.Dest_X = player_target.X; Globals.gamedata.my_char.Dest_Y = player_target.Y; Globals.gamedata.my_char.Dest_Z = player_target.Z; found = true; } break; case TargetType.NPC: NPCInfo npc_target = null; Globals.NPCLock.EnterReadLock(); try { npc_target = Util.GetNPC(Globals.gamedata.my_char.MoveTarget); } finally { Globals.NPCLock.ExitReadLock(); } if (npc_target != null) { Globals.gamedata.my_char.Dest_X = npc_target.X; Globals.gamedata.my_char.Dest_Y = npc_target.Y; Globals.gamedata.my_char.Dest_Z = npc_target.Z; found = true; } break; case TargetType.ITEM: ItemInfo item_target = null; Globals.ItemLock.EnterReadLock(); try { item_target = Util.GetItem(Globals.gamedata.my_char.MoveTarget); } finally { Globals.ItemLock.ExitReadLock(); } if (item_target != null) { Globals.gamedata.my_char.Dest_X = item_target.X; Globals.gamedata.my_char.Dest_Y = item_target.Y; Globals.gamedata.my_char.Dest_Z = item_target.Z; found = true; } break; } if (!found) { Globals.gamedata.my_char.Dest_X = Globals.gamedata.my_char.X; Globals.gamedata.my_char.Dest_Y = Globals.gamedata.my_char.Y; Globals.gamedata.my_char.Dest_Z = Globals.gamedata.my_char.Z; } } //move me towards my target vx = Globals.gamedata.my_char.Dest_X - Globals.gamedata.my_char.X; vy = Globals.gamedata.my_char.Dest_Y - Globals.gamedata.my_char.Y; vz = Globals.gamedata.my_char.Dest_Z - Globals.gamedata.my_char.Z; //movespeed = ((float)my_char.RunSpeed)*ch.MoveSpeedMult; movespeed = Globals.gamedata.my_char.RunSpeed * Globals.gamedata.my_char.MoveSpeedMult; time = System.Convert.ToSingle(((System.TimeSpan)(System.DateTime.Now - Globals.gamedata.my_char.lastMoveTime)).Milliseconds) * Globals.INV_THOUSAND; vxx = System.Convert.ToSingle(Math.Sqrt(vx * vx + vy * vy + vz * vz)); if (vxx != 0) { vxx = Util.Float_Cap((movespeed * time) / vxx); } vx *= vxx; vy *= vxx; vz *= vxx; Globals.gamedata.my_char.X += vx; Globals.gamedata.my_char.Y += vy; Globals.gamedata.my_char.Z += vz; Globals.gamedata.my_char.lastMoveTime = System.DateTime.Now; if ((Globals.gamedata.my_char.MoveTarget == 0) && (Math.Sqrt(Math.Pow(Globals.gamedata.my_char.X - Globals.gamedata.my_char.Dest_X, 2) + Math.Pow(Globals.gamedata.my_char.Y - Globals.gamedata.my_char.Dest_Y, 2) + Math.Pow(Globals.gamedata.my_char.Z - Globals.gamedata.my_char.Dest_Z, 2)) < Globals.THRESHOLD)) { Globals.gamedata.my_char.Moving = false; } } } catch { Globals.l2net_home.Add_Error("crash: Animate self"); } ///////////////////////Animate Pet if (Globals.gamedata.my_pet.ID != 0) { try { if (Globals.gamedata.my_pet.Moving == true) { if (Globals.gamedata.my_pet.MoveTarget != 0) { found = false; //need to set the dest switch (Globals.gamedata.my_pet.MoveTargetType) { case TargetType.ERROR: case TargetType.NONE: //shouldn't get this ever //Globals.l2net_home.Add_OnlyDebug("MoveToPawn MoveTargetType invalid - pet: " + Globals.gamedata.my_pet.Name + ":" + Globals.gamedata.my_pet.ID.ToString() + "--: " + Globals.gamedata.my_pet.MoveTarget.ToString()); break; case TargetType.SELF: Globals.gamedata.my_pet.Dest_X = Globals.gamedata.my_char.X; Globals.gamedata.my_pet.Dest_Y = Globals.gamedata.my_char.Y; Globals.gamedata.my_pet.Dest_Z = Globals.gamedata.my_char.Z; found = true; break; case TargetType.MYPET: //shouldn't get this ever... Globals.gamedata.my_pet.Dest_X = Globals.gamedata.my_pet.X; Globals.gamedata.my_pet.Dest_Y = Globals.gamedata.my_pet.Y; Globals.gamedata.my_pet.Dest_Z = Globals.gamedata.my_pet.Z; found = true; break; case TargetType.MYPET1: //shouldn't get this ever... Globals.gamedata.my_pet1.Dest_X = Globals.gamedata.my_pet1.X; Globals.gamedata.my_pet1.Dest_Y = Globals.gamedata.my_pet1.Y; Globals.gamedata.my_pet1.Dest_Z = Globals.gamedata.my_pet1.Z; found = true; break; case TargetType.MYPET2: //shouldn't get this ever... Globals.gamedata.my_pet2.Dest_X = Globals.gamedata.my_pet2.X; Globals.gamedata.my_pet2.Dest_Y = Globals.gamedata.my_pet2.Y; Globals.gamedata.my_pet2.Dest_Z = Globals.gamedata.my_pet2.Z; found = true; break; case TargetType.MYPET3: //shouldn't get this ever... Globals.gamedata.my_pet3.Dest_X = Globals.gamedata.my_pet3.X; Globals.gamedata.my_pet3.Dest_Y = Globals.gamedata.my_pet3.Y; Globals.gamedata.my_pet3.Dest_Z = Globals.gamedata.my_pet3.Z; found = true; break; case TargetType.PLAYER: CharInfo player_target = null; Globals.PlayerLock.EnterReadLock(); try { player_target = Util.GetChar(Globals.gamedata.my_pet.MoveTarget); } finally { Globals.PlayerLock.ExitReadLock(); } if (player_target != null) { Globals.gamedata.my_pet.Dest_X = player_target.X; Globals.gamedata.my_pet.Dest_Y = player_target.Y; Globals.gamedata.my_pet.Dest_Z = player_target.Z; found = true; } break; case TargetType.NPC: NPCInfo npc_target = null; Globals.NPCLock.EnterReadLock(); try { npc_target = Util.GetNPC(Globals.gamedata.my_pet.MoveTarget); } finally { Globals.NPCLock.ExitReadLock(); } if (npc_target != null) { Globals.gamedata.my_pet.Dest_X = npc_target.X; Globals.gamedata.my_pet.Dest_Y = npc_target.Y; Globals.gamedata.my_pet.Dest_Z = npc_target.Z; found = true; } break; case TargetType.ITEM: ItemInfo item_target = null; Globals.ItemLock.EnterReadLock(); try { item_target = Util.GetItem(Globals.gamedata.my_pet.MoveTarget); } finally { Globals.ItemLock.ExitReadLock(); } if (item_target != null) { Globals.gamedata.my_pet.Dest_X = item_target.X; Globals.gamedata.my_pet.Dest_Y = item_target.Y; Globals.gamedata.my_pet.Dest_Z = item_target.Z; found = true; } break; } if (!found) { Globals.gamedata.my_pet.Dest_X = Globals.gamedata.my_pet.X; Globals.gamedata.my_pet.Dest_Y = Globals.gamedata.my_pet.Y; Globals.gamedata.my_pet.Dest_Z = Globals.gamedata.my_pet.Z; } } //move me towards my target vx = Globals.gamedata.my_pet.Dest_X - Globals.gamedata.my_pet.X; vy = Globals.gamedata.my_pet.Dest_Y - Globals.gamedata.my_pet.Y; vz = Globals.gamedata.my_pet.Dest_Z - Globals.gamedata.my_pet.Z; //movespeed = ((float)my_char.RunSpeed)*ch.MoveSpeedMult; movespeed = Globals.gamedata.my_pet.RunSpeed * Globals.gamedata.my_pet.MoveSpeedMult; time = System.Convert.ToSingle(((System.TimeSpan)(System.DateTime.Now - Globals.gamedata.my_pet.lastMoveTime)).Milliseconds) * Globals.INV_THOUSAND; vxx = System.Convert.ToSingle(Math.Sqrt(vx * vx + vy * vy + vz * vz)); if (vxx != 0) { vxx = Util.Float_Cap((movespeed * time) / vxx); } vx *= vxx; vy *= vxx; vz *= vxx; Globals.gamedata.my_pet.X += vx; Globals.gamedata.my_pet.Y += vy; Globals.gamedata.my_pet.Z += vz; Globals.gamedata.my_pet.lastMoveTime = System.DateTime.Now; if ((Globals.gamedata.my_pet.MoveTarget == 0) && (Math.Sqrt(Math.Pow(Globals.gamedata.my_pet.X - Globals.gamedata.my_pet.Dest_X, 2) + Math.Pow(Globals.gamedata.my_pet.Y - Globals.gamedata.my_pet.Dest_Y, 2) + Math.Pow(Globals.gamedata.my_pet.Z - Globals.gamedata.my_pet.Dest_Z, 2)) < Globals.THRESHOLD)) { Globals.gamedata.my_pet.Moving = false; } } } catch { Globals.l2net_home.Add_Error("crash: Animate pet"); } } ///////////////////////Animate other chars Globals.PlayerLock.EnterReadLock(); try { foreach (CharInfo player in Globals.gamedata.nearby_chars.Values) { if (player.Moving) { if (player.MoveTarget != 0) { found = false; //need to set the dest switch (player.MoveTargetType) { case TargetType.ERROR: case TargetType.NONE: //shouldn't get this ever... //Globals.l2net_home.Add_OnlyDebug("MoveToPawn MoveTargetType invalid - pc: " + player.Name + ":" + player.ID.ToString() + "--: " + player.MoveTarget.ToString()); break; case TargetType.SELF: player.Dest_X = Globals.gamedata.my_char.X; player.Dest_Y = Globals.gamedata.my_char.Y; player.Dest_Z = Globals.gamedata.my_char.Z; found = true; break; case TargetType.MYPET: player.Dest_X = Globals.gamedata.my_pet.X; player.Dest_Y = Globals.gamedata.my_pet.Y; player.Dest_Z = Globals.gamedata.my_pet.Z; found = true; break; case TargetType.MYPET1: player.Dest_X = Globals.gamedata.my_pet1.X; player.Dest_Y = Globals.gamedata.my_pet1.Y; player.Dest_Z = Globals.gamedata.my_pet1.Z; found = true; break; case TargetType.MYPET2: player.Dest_X = Globals.gamedata.my_pet2.X; player.Dest_Y = Globals.gamedata.my_pet2.Y; player.Dest_Z = Globals.gamedata.my_pet2.Z; found = true; break; case TargetType.MYPET3: player.Dest_X = Globals.gamedata.my_pet3.X; player.Dest_Y = Globals.gamedata.my_pet3.Y; player.Dest_Z = Globals.gamedata.my_pet3.Z; found = true; break; case TargetType.PLAYER: CharInfo player_target = null; //no need to lock... we already have a writer lock player_target = Util.GetChar(Globals.gamedata.my_char.MoveTarget); if (player_target != null) { player.Dest_X = player_target.X; player.Dest_Y = player_target.Y; player.Dest_Z = player_target.Z; found = true; } break; case TargetType.NPC: NPCInfo npc_target = null; Globals.NPCLock.EnterReadLock(); try { npc_target = Util.GetNPC(player.MoveTarget); } finally { Globals.NPCLock.ExitReadLock(); } if (npc_target != null) { player.Dest_X = npc_target.X; player.Dest_Y = npc_target.Y; player.Dest_Z = npc_target.Z; found = true; } break; case TargetType.ITEM: ItemInfo item_target = null; Globals.ItemLock.EnterReadLock(); try { item_target = Util.GetItem(player.MoveTarget); } //unlock finally { Globals.ItemLock.ExitReadLock(); } if (item_target != null) { player.Dest_X = item_target.X; player.Dest_Y = item_target.Y; player.Dest_Z = item_target.Z; found = true; } break; } if (!found) { player.Dest_X = player.X; player.Dest_Y = player.Y; player.Dest_Z = player.Z; } } vx = player.Dest_X - player.X; vy = player.Dest_Y - player.Y; vz = player.Dest_Z - player.Z; if (player.isRunning != 0) { movespeed = player.RunSpeed * player.MoveSpeedMult; } else { movespeed = player.WalkSpeed * player.MoveSpeedMult; } time = System.Convert.ToSingle(((System.TimeSpan)(System.DateTime.Now - player.lastMoveTime)).Milliseconds) * Globals.INV_THOUSAND; vxx = System.Convert.ToSingle(Math.Sqrt(vx * vx + vy * vy + vz * vz)); if (vxx != 0) { vxx = Util.Float_Cap((movespeed * time) / vxx); } vx *= vxx; vy *= vxx; vz *= vxx; player.X += Util.Float_Int32(vx); player.Y += Util.Float_Int32(vy); player.Z += Util.Float_Int32(vz); player.lastMoveTime = System.DateTime.Now; if ((player.MoveTarget == 0) && (Math.Sqrt(Math.Pow(player.X - player.Dest_X, 2) + Math.Pow(player.Y - player.Dest_Y, 2) + Math.Pow(player.Z - player.Dest_Z, 2)) < Globals.THRESHOLD)) { player.Moving = false; } } } }//unlock catch { Globals.l2net_home.Add_Error("crash: Animate other players"); } finally { Globals.PlayerLock.ExitReadLock(); } //animate npcs Globals.NPCLock.EnterReadLock(); try { foreach (NPCInfo npc in Globals.gamedata.nearby_npcs.Values) { if (npc.Moving) { if (npc.MoveTarget != 0) { found = false; //need to set the dest switch (npc.MoveTargetType) { case TargetType.ERROR: case TargetType.NONE: //shouldn't get this ever... //Globals.l2net_home.Add_OnlyDebug("MoveToPawn MoveTargetType invalid - npc: " + npc.Name + ":" + npc.ID.ToString() + "--: " + npc.MoveTarget.ToString()); break; case TargetType.SELF: npc.Dest_X = Globals.gamedata.my_char.X; npc.Dest_Y = Globals.gamedata.my_char.Y; npc.Dest_Z = Globals.gamedata.my_char.Z; found = true; break; case TargetType.MYPET: npc.Dest_X = Globals.gamedata.my_pet.X; npc.Dest_Y = Globals.gamedata.my_pet.Y; npc.Dest_Z = Globals.gamedata.my_pet.Z; found = true; break; case TargetType.MYPET1: npc.Dest_X = Globals.gamedata.my_pet1.X; npc.Dest_Y = Globals.gamedata.my_pet1.Y; npc.Dest_Z = Globals.gamedata.my_pet1.Z; found = true; break; case TargetType.MYPET2: npc.Dest_X = Globals.gamedata.my_pet2.X; npc.Dest_Y = Globals.gamedata.my_pet2.Y; npc.Dest_Z = Globals.gamedata.my_pet2.Z; found = true; break; case TargetType.MYPET3: npc.Dest_X = Globals.gamedata.my_pet3.X; npc.Dest_Y = Globals.gamedata.my_pet3.Y; npc.Dest_Z = Globals.gamedata.my_pet3.Z; found = true; break; case TargetType.PLAYER: CharInfo player_target = null; Globals.PlayerLock.EnterReadLock(); try { player_target = Util.GetChar(npc.MoveTarget); } finally { Globals.PlayerLock.ExitReadLock(); } if (player_target != null) { npc.Dest_X = player_target.X; npc.Dest_Y = player_target.Y; npc.Dest_Z = player_target.Z; found = true; } break; case TargetType.NPC: NPCInfo npc_target = null; //no need to lock... we already have a writer lock npc_target = Util.GetNPC(npc.MoveTarget); if (npc_target != null) { npc.Dest_X = npc_target.X; npc.Dest_Y = npc_target.Y; npc.Dest_Z = npc_target.Z; found = true; } break; case TargetType.ITEM: ItemInfo item_target = null; Globals.ItemLock.EnterReadLock(); try { item_target = Util.GetItem(npc.MoveTarget); } finally { Globals.ItemLock.ExitReadLock(); } if (item_target != null) { npc.Dest_X = item_target.X; npc.Dest_Y = item_target.Y; npc.Dest_Z = item_target.Z; found = true; } break; }//end of switch if (!found) { npc.Dest_X = npc.X; npc.Dest_Y = npc.Y; npc.Dest_Z = npc.Z; } } vx = npc.Dest_X - npc.X; vy = npc.Dest_Y - npc.Y; vz = npc.Dest_Z - npc.Z; if (npc.isRunning != 0) { movespeed = npc.RunSpeed * npc.MoveSpeedMult; } else { movespeed = npc.WalkSpeed * npc.MoveSpeedMult; } time = System.Convert.ToSingle(((System.TimeSpan)(System.DateTime.Now - npc.lastMoveTime)).Milliseconds) * Globals.INV_THOUSAND; vxx = System.Convert.ToSingle(Math.Sqrt(vx * vx + vy * vy + vz * vz)); if (vxx != 0) { vxx = Util.Float_Cap((movespeed * time) / vxx); } vx *= vxx; vy *= vxx; vz *= vxx; npc.X += Util.Float_Int32(vx); npc.Y += Util.Float_Int32(vy); npc.Z += Util.Float_Int32(vz); npc.lastMoveTime = System.DateTime.Now; if ((npc.MoveTarget == 0) && (Math.Sqrt(Math.Pow(npc.X - npc.Dest_X, 2) + Math.Pow(npc.Y - npc.Dest_Y, 2) + Math.Pow(npc.Z - npc.Dest_Z, 2)) < Globals.THRESHOLD)) { npc.Moving = false; } } } }//unlock catch { Globals.l2net_home.Add_Error("crash: Animate npcs"); } finally { Globals.NPCLock.ExitReadLock(); } }//end of AnimateStuff