Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.64 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Linq;
  5. using DofusEmµ.Utils;
  6. using DofusEmµ.World;
  7. using DofusEmµ.Parsing;
  8. using DofusEmµ.Utils.Socket;
  9.  
  10. namespace DofusEmµ.Game
  11. {
  12.     public class Zaap
  13.     {
  14.         #region Constructor
  15.         public Zaap(Character owner)
  16.         {
  17.             this.ZaapList = new List<int>();
  18.             this.Owner = owner;
  19.         }
  20.         #endregion
  21.  
  22.         #region Database use
  23.         public void LoadZaap()
  24.         {
  25.             this.ZaapList.Clear();
  26.  
  27.             foreach (Dictionary<string, string> Row in Sql.ReadRequestExtended("SELECT * FROM player_zaap WHERE PlayerId = '" + Owner.ID + "'"))
  28.             {
  29.                 this.AddZaap(int.Parse(Row["MapId"]));
  30.             }
  31.         }
  32.  
  33.         public void SaveZaap()
  34.         {
  35.             Dictionary<string, string>[] SaveZaap = Sql.ReadRequestExtended("SELECT * FROM player_zaap WHERE PlayerId = '" + this.Owner.ID + "'");
  36.  
  37.             List<int> SaveId = (from entry in SaveZaap
  38.                                  select int.Parse(entry["MapId"])).ToList();
  39.  
  40.             foreach (int mapId in ZaapList)
  41.             {
  42.                 if (!SaveId.Contains(mapId))
  43.                 {
  44.                     Sql.ExecuteRequest("INSERT INTO player_zaap " +
  45.                         "(PlayerId, MapId) VALUES " +
  46.                         "(" +
  47.                         String.Format("'{0}', '{1}'",
  48.                         Owner.ID, mapId) +
  49.                         ")");
  50.                 }
  51.             }
  52.         }
  53.         #endregion
  54.  
  55.         #region Functions
  56.         public void AddZaap(int mapId)
  57.         {
  58.             this.ZaapList.Add(mapId);
  59.         }
  60.  
  61.         public bool hasZaap(int mapId)
  62.         {
  63.             return ZaapList.Contains(mapId);
  64.         }
  65.         #endregion
  66.  
  67.         #region Proprieties
  68.         public Character Owner
  69.         {
  70.             get;
  71.             set;
  72.         }
  73.  
  74.         public List<int> ZaapList
  75.         {
  76.             get;
  77.             set;
  78.         }
  79.  
  80.         public bool isZaaping
  81.         {
  82.             get;
  83.             set;
  84.         }
  85.         #endregion
  86.  
  87.         #region Patterns
  88.         public string PatternZaap
  89.         {
  90.             get
  91.             {
  92.                 string pattern = "";
  93.  
  94.                 foreach (int mapId in ZaapList)
  95.                 {
  96.                     if (ZaapServerManager.hasZaap(mapId))
  97.                     {
  98.                         pattern += mapId + ";" + ZaapServerManager.zaapCost(Owner.Map, MapsServerManager.Maps[mapId]) + "|";
  99.                     }
  100.                 }
  101.  
  102.                 return pattern.Substring(0, (pattern.Length > 0 ? pattern.Length - 1 : 0));
  103.             }
  104.         }
  105.         #endregion
  106.  
  107.         #region Send Functions
  108.         public void SendMenu(TCPSocket Client, int cellId)
  109.         {
  110.             if (!ZaapServerManager.hasZaap(Owner.Map.ID))
  111.                 return;
  112.             if (!hasZaap(Owner.Map.ID))
  113.             {
  114.                 AddZaap(Owner.Map.ID);
  115.                 Client.SendData(PaquetType.Game.MessageInfo + "024");
  116.             }
  117.             isZaaping = true;
  118.             Client.SendData(PaquetType.Game.InGame.Zaap.Menu + ZaapServerManager.zaapCost(Owner.Map, MapsServerManager.Maps[Owner.Spawn]) + Owner.Spawn + "|" + PatternZaap);
  119.         }
  120.  
  121.         public void SendClose(TCPSocket Client)
  122.         {
  123.             if (!isZaaping)
  124.                 return;
  125.             isZaaping = false;
  126.             Client.SendData(PaquetType.Game.InGame.Zaap.Close);
  127.         }
  128.  
  129.         public void SendSave(TCPSocket Client, int cellId)
  130.         {
  131.             if (!ZaapServerManager.hasZaap(Owner.Map.ID))
  132.                 return;
  133.             Owner.Spawn = Owner.Map.ID;
  134.             Client.SendData(PaquetType.Game.MessageInfo + "06");
  135.         }
  136.  
  137.         public void SendUse(TCPSocket Client, int mapId)
  138.         {
  139.             if (!isZaaping)
  140.             {
  141.                 Player.GetPlayerByCharName(Owner.Name).Kick();
  142.                 return;
  143.             }
  144.             if (!hasZaap(mapId))
  145.             {
  146.                 Player.GetPlayerByCharName(Owner.Name).Kick();
  147.                 return;
  148.             }
  149.             int cellId = ZaapServerManager.zaapCellId(mapId);
  150.             int cost = ZaapServerManager.zaapCost(Owner.Map, MapsServerManager.Maps[mapId]);
  151.             if (Owner.CurrentStats.Kamas < cost)
  152.                 return;
  153.             Owner.CurrentStats.Kamas -= cost;
  154.  
  155.             /*if (MapsServerManager.Maps[mapId] == null)
  156.             {
  157.                 ((Player)Client.Tag).Log("La map n'est pas implantee, Zaap refuse (mapID='" + mapId + "')");
  158.                 Client.SendData(PaquetType.Game.InGame.Zaap.Use + "E");
  159.                 return;
  160.             }
  161.             if (MapsServerManager.Maps[mapId].Cases[cellId] == null)
  162.             {
  163.                 ((Player)Client.Tag).Log("La cellule associee au zaap n'est pas implantee, Zaap refuse (mapID='" + mapId + "')");
  164.                 Client.SendData(PaquetType.Game.InGame.Zaap.Use + "E");
  165.                 return;
  166.             }
  167.             if (!MapsServerManager.Maps[mapId].Cases[cellId].IsSightBlocker)
  168.             {
  169.                 ((Player)Client.Tag).Log("La cellule associee au zaap n'est pas 'walkable', Zaap refuse (mapID='" + mapId + "')");
  170.                 Client.SendData(PaquetType.Game.InGame.Zaap.Use + "E");
  171.                 return;
  172.             }*/
  173.  
  174.             Mouvement.PlayerLeaveMap(Client);
  175.             Mouvement.PlayerChangeMap(Client, MapsServerManager.Maps[mapId], MapsServerManager.Maps[mapId].Cases[cellId]);
  176.             Owner.SendStats(Client);
  177.             SendClose(Client);
  178.         }
  179.         #endregion
  180.     }
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement