Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Linq;
- using DofusEmµ.Utils;
- using DofusEmµ.World;
- using DofusEmµ.Parsing;
- using DofusEmµ.Utils.Socket;
- namespace DofusEmµ.Game
- {
- public class Zaap
- {
- #region Constructor
- public Zaap(Character owner)
- {
- this.ZaapList = new List<int>();
- this.Owner = owner;
- }
- #endregion
- #region Database use
- public void LoadZaap()
- {
- this.ZaapList.Clear();
- foreach (Dictionary<string, string> Row in Sql.ReadRequestExtended("SELECT * FROM player_zaap WHERE PlayerId = '" + Owner.ID + "'"))
- {
- this.AddZaap(int.Parse(Row["MapId"]));
- }
- }
- public void SaveZaap()
- {
- Dictionary<string, string>[] SaveZaap = Sql.ReadRequestExtended("SELECT * FROM player_zaap WHERE PlayerId = '" + this.Owner.ID + "'");
- List<int> SaveId = (from entry in SaveZaap
- select int.Parse(entry["MapId"])).ToList();
- foreach (int mapId in ZaapList)
- {
- if (!SaveId.Contains(mapId))
- {
- Sql.ExecuteRequest("INSERT INTO player_zaap " +
- "(PlayerId, MapId) VALUES " +
- "(" +
- String.Format("'{0}', '{1}'",
- Owner.ID, mapId) +
- ")");
- }
- }
- }
- #endregion
- #region Functions
- public void AddZaap(int mapId)
- {
- this.ZaapList.Add(mapId);
- }
- public bool hasZaap(int mapId)
- {
- return ZaapList.Contains(mapId);
- }
- #endregion
- #region Proprieties
- public Character Owner
- {
- get;
- set;
- }
- public List<int> ZaapList
- {
- get;
- set;
- }
- public bool isZaaping
- {
- get;
- set;
- }
- #endregion
- #region Patterns
- public string PatternZaap
- {
- get
- {
- string pattern = "";
- foreach (int mapId in ZaapList)
- {
- if (ZaapServerManager.hasZaap(mapId))
- {
- pattern += mapId + ";" + ZaapServerManager.zaapCost(Owner.Map, MapsServerManager.Maps[mapId]) + "|";
- }
- }
- return pattern.Substring(0, (pattern.Length > 0 ? pattern.Length - 1 : 0));
- }
- }
- #endregion
- #region Send Functions
- public void SendMenu(TCPSocket Client, int cellId)
- {
- if (!ZaapServerManager.hasZaap(Owner.Map.ID))
- return;
- if (!hasZaap(Owner.Map.ID))
- {
- AddZaap(Owner.Map.ID);
- Client.SendData(PaquetType.Game.MessageInfo + "024");
- }
- isZaaping = true;
- Client.SendData(PaquetType.Game.InGame.Zaap.Menu + ZaapServerManager.zaapCost(Owner.Map, MapsServerManager.Maps[Owner.Spawn]) + Owner.Spawn + "|" + PatternZaap);
- }
- public void SendClose(TCPSocket Client)
- {
- if (!isZaaping)
- return;
- isZaaping = false;
- Client.SendData(PaquetType.Game.InGame.Zaap.Close);
- }
- public void SendSave(TCPSocket Client, int cellId)
- {
- if (!ZaapServerManager.hasZaap(Owner.Map.ID))
- return;
- Owner.Spawn = Owner.Map.ID;
- Client.SendData(PaquetType.Game.MessageInfo + "06");
- }
- public void SendUse(TCPSocket Client, int mapId)
- {
- if (!isZaaping)
- {
- Player.GetPlayerByCharName(Owner.Name).Kick();
- return;
- }
- if (!hasZaap(mapId))
- {
- Player.GetPlayerByCharName(Owner.Name).Kick();
- return;
- }
- int cellId = ZaapServerManager.zaapCellId(mapId);
- int cost = ZaapServerManager.zaapCost(Owner.Map, MapsServerManager.Maps[mapId]);
- if (Owner.CurrentStats.Kamas < cost)
- return;
- Owner.CurrentStats.Kamas -= cost;
- /*if (MapsServerManager.Maps[mapId] == null)
- {
- ((Player)Client.Tag).Log("La map n'est pas implantee, Zaap refuse (mapID='" + mapId + "')");
- Client.SendData(PaquetType.Game.InGame.Zaap.Use + "E");
- return;
- }
- if (MapsServerManager.Maps[mapId].Cases[cellId] == null)
- {
- ((Player)Client.Tag).Log("La cellule associee au zaap n'est pas implantee, Zaap refuse (mapID='" + mapId + "')");
- Client.SendData(PaquetType.Game.InGame.Zaap.Use + "E");
- return;
- }
- if (!MapsServerManager.Maps[mapId].Cases[cellId].IsSightBlocker)
- {
- ((Player)Client.Tag).Log("La cellule associee au zaap n'est pas 'walkable', Zaap refuse (mapID='" + mapId + "')");
- Client.SendData(PaquetType.Game.InGame.Zaap.Use + "E");
- return;
- }*/
- Mouvement.PlayerLeaveMap(Client);
- Mouvement.PlayerChangeMap(Client, MapsServerManager.Maps[mapId], MapsServerManager.Maps[mapId].Cases[cellId]);
- Owner.SendStats(Client);
- SendClose(Client);
- }
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement