Esempio n. 1
0
        public void Cancel(Player player)
        {
            if (!(player.Controller is PlayerTradeController))
                return;

            ((PlayerTradeController)player.Controller).Cancel(player);
        }
Esempio n. 2
0
        public WorldPosition GetBindPoint(Player player)
        {
            WorldPosition pos = IslandOfDawnSpawn.Clone();
            int mapId = 13;

            if (Communication.Global.MapService.IsDungeon(player.Position.MapId))
            {
                if (((ADungeon) player.Instance).ParentMapId != 0 &&
                    Data.Data.CampfireTemplates.ContainsKey(((ADungeon) player.Instance).ParentMapId))
                    mapId = ((ADungeon) player.Instance).ParentMapId;
            }
            else
                mapId = player.Position.MapId;

            if (Data.Data.CampfireTemplates.ContainsKey(mapId))
                foreach (var template in Data.Data.CampfireTemplates[mapId])
                {
                    if(template.Type == 1)
                        continue;

                    if (template.Position.DistanceTo(player.Position) < player.Position.DistanceTo(pos))
                        pos = template.Position.Clone();
                }

            pos.X += new Random().Next(75, 100);

            return pos;
        }
Esempio n. 3
0
        public void ProcessRequest(int uid, bool isAccepted, Player arrivedFrom = null)
        {
            Request request;
            lock (RequestsLock)
            {
                if (!WorldRequests.ContainsKey(uid))
                    return;

                request = WorldRequests[uid];
                request.InProgress = true;
            }

            // Someone tried to accept/decline request that don't belongs to him
           if ((request.Target != null && request.Target != arrivedFrom) 
                || (request.Target == null && !request.Owner.Party.PartyMembers.Contains(arrivedFrom)))
                return;
            
            IRequestAction action = null;
            switch (request.Type)
            {
                case RequestType.PartyInvite:
                    action = new PartyAction(request);
                    break;
                case RequestType.DuelInvite:
                    action = new DuelAction(request);
                    break;
                case RequestType.GuildCreate:
                        action = new GuildAction(request, arrivedFrom);
                    break;
                case RequestType.GuildInvite:
                    action = new GuildInviteAction(request);
                    break;
                case RequestType.TradeStart:
                    action = new TradeAction(request);
                    break;
            }

            // process request
            try
            {
                if(action == null)
                    return;

                if (isAccepted)
                    action.Accepted();
                else
                    action.Declined();
            }
            catch(Exception e)
            {
                Log.Error("Process request#{0} exception: {1}", (int)request.Type, e.ToString());
            }
            finally
            {
                // Ensure that we remove request, no matter what happens
                if (!request.Blocking)
                    lock (RequestsLock)
                        UnregisterRequest(request);
            }
        }
 public void PlayerEndGame(Player player)
 {
     //todo Maybe better create a callback in IController? smth like OnEndGame?
     if(player.Controller is PlayerTradeController)
         ((PlayerTradeController)player.Controller).Cancel(player);
     SetController(player, null);
 }
Esempio n. 5
0
        public void PlayerDied(Player player)
        {
            WorldPosition bindPoint = GetNearestBindPoint(player);
            player.ClosestBindPoint = bindPoint;

            Global.Global.VisibleService.Send(player, new SpCreatureDied(player));
        }
Esempio n. 6
0
 public void SaveSkills(Player player)
 {
     foreach (var skill in player.Skills)
     {
         SaveSkill(player, skill);
     }
 }
Esempio n. 7
0
        public QuestData LoadQuest(Player player, int questid)
        {
            string SQL = "SELECT * FROM `quests` WHERE "
                + "`questid` = ?qid AND `characterid` = ?pid";
            MySqlCommand cmd = new MySqlCommand(SQL, QuestDAOConnection);
            cmd.Parameters.AddWithValue("?qid", questid);
            cmd.Parameters.AddWithValue("?pid", player.Id);
            MySqlDataReader LoadQuestReader = cmd.ExecuteReader();

            QuestData quest = new QuestData(questid);
            if (LoadQuestReader.HasRows)
            {
                while (LoadQuestReader.Read())
                {
                    quest = new QuestData(questid)
                    {
                        QuestId = LoadQuestReader.GetInt32(1),
                        Status = (QuestStatus)Enum.Parse(typeof(QuestStatus), LoadQuestReader.GetString(2)),
                        Step = LoadQuestReader.GetInt32(3),
                        Counters = LoadQuestReader.GetString(4).Split(',').Select(n => int.Parse(n)).ToList()
                    };
                }
            }
            LoadQuestReader.Close();

            return quest;
        }
Esempio n. 8
0
        public void OnPlayerEnterWorld(IConnection connection, Player player)
        {
            string uidHex = BitConverter.GetBytes(player.UID).ToHex()
                + BitConverter.GetBytes(ObjectFamily.Player.GetHashCode()).ToHex();

            new SendPacket("8FCD00000000").Send(connection); //1725 EU
            new SendPacket("0D9600000000").Send(connection); //1725 EU

            //new SpFriendList(pState.Player.Friends).Send(connection);
            //new SpFriendUpdate(pState.Player.Friends).Send(connection);

            new SendPacket("A7F20000000000000000").Send(connection); //1725 EU
            new SendPacket("03E70000000000000000").Send(connection); //1725 EU

            new SpCharacterPosition(player).Send(connection);

            FlyController flyController = player.Controller as FlyController;
            if (flyController != null)
                flyController.EndFly(player.Position.MapId);

            new SendPacket("E1EB" + uidHex + "7CC4000001FFFFFF7F").Send(connection); //1725 EU

            new SpCharacterStats(player).Send(connection);
            new SpCharacterGatherstats(player.PlayerCraftStats).Send(connection);

            CraftService.UpdateCraftRecipes(player);

            player.LastOnlineUtc = Funcs.GetRoundedUtc();
        }
        public void Cancel(Player player)
        {
            lock (TradeLock)
            {
                if (IsTradeFinished())
                    return;

                SystemMessages.OpponentCanceledTheTrade(player.PlayerData.Name).Send(Player1, Player2);

                lock (Storage1.ItemsLock)
                {
                    foreach (var item in Storage1.Items.Values)
                        Communication.Global.StorageService.AddItem(Player1, Player1.Inventory, item);

                    Player1.Inventory.Money += Storage1.Money;
                }

                lock (Storage2.ItemsLock)
                {
                    foreach (var item in Storage2.Items.Values)
                        Communication.Global.StorageService.AddItem(Player2, Player2.Inventory, item);

                    Player2.Inventory.Money += Storage2.Money;
                }

                PreRelease();
                Communication.Global.ControllerService.SetController(Player1, new DefaultController());
                Communication.Global.ControllerService.SetController(Player2, new DefaultController());
                PostRelease();
            }
        }
Esempio n. 10
0
        public QuestData LoadQuest(Player player, int questId)
        {
            string cmdString = "SELECT * FROM questdata WHERE QuestId=?qid AND PlayerId=?pid";
            MySqlCommand command = new MySqlCommand(cmdString, QuestDAOConnection);
            command.Parameters.AddWithValue("?qid", questId);
            command.Parameters.AddWithValue("?pid", player.Id);
            MySqlDataReader reader = command.ExecuteReader();

            QuestData quest = new QuestData(questId);
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    quest = new QuestData(questId)
                    {
                        QuestId = reader.GetInt32(1),
                        Status = (QuestStatus)Enum.Parse(typeof(QuestStatus), reader.GetString(2)),
                        Step = reader.GetInt32(3),
                        Counters = reader.GetString(4).Split(',').Select(n => int.Parse(n)).ToList()
                    };
                }
            }
            reader.Close();

            return quest;
        }
        public override List<int> GetParticipantVillagers(Player player)
        {
            if (!IsCountersComplete(player))
                return new List<int>();

            return new List<int> {Task.DeliverToFullId};
        }
Esempio n. 12
0
 public void ApplyAbility(Player player)
 {
     foreach (var abi in player.Abilities.Values)
     {
         AddAbility(player, abi.Key, abi.Value);
     }
 }
        public override List<int> GetParticipantMonsters(Player player)
        {
            if (IsCountersComplete(player))
                return new List<int>();

            return new List<int>(Task.DroppedFrom);
        }
Esempio n. 14
0
 public SpTradeHideWindow(Player player1, Player player2, int tradeId, int type = 1)
 {
     Player1 = player1;
     Player2 = player2;
     TradeId = tradeId;
     Type = type;
 }
Esempio n. 15
0
        public void TrySetDefaultController(Player player)
        {
            if (player.Controller is DefaultController)
                return;

            SetController(player, new DefaultController());
        }
Esempio n. 16
0
        public void RemoveItem(Player player, int slot, int count)
        {
            if (!(player.Controller is PlayerTradeController))
                return;

            ((PlayerTradeController)player.Controller).RemoveItem(player, slot, count);
        }
Esempio n. 17
0
        public void ProcessDamage(Player player)
        {
            if(player.Duel == null)
                return;

            player.Duel.LastKickUtc = Funcs.GetCurrentMilliseconds();
        }
Esempio n. 18
0
        public void StartEmotion(Player player, int emoteId)
        {
            player.CurrentEmotion = new KeyValuePair<int, int>(emoteId, (int)DateTime.Now.Ticks);
            Communication.Global.VisibleService.Send(player, new SpCharacterEmotions(player, emoteId));

            //TODO find emotions in SpCharacterInfo
        }
        public void AddItem(Player arrivedFrom, int slot, int count)
        {
            lock (TradeLock)
            {
                if (IsTradeFinished())
                    return;

                // should be impossible, but it's better to check
                if (arrivedFrom != Player1 && arrivedFrom != Player2)
                    return;

                Storage storage = arrivedFrom.Equals(Player1) ? Storage1 : Storage2;
                if (storage.Locked)
                {
                    SystemMessages.TradeListLocked.Send(arrivedFrom);
                    return;
                }

                StorageItem item = Communication.Global.StorageService.GetItemBySlot(arrivedFrom.Inventory, slot + 20);
                if (item == null)
                    return;

                if (!Communication.Global.StorageService.AddItem(arrivedFrom, storage, item.ItemId, count))
                    return;

                CheckLock(storage.Equals(Storage1) ? Storage2 : Storage1);
                Communication.Global.StorageService.RemoveItem(arrivedFrom, arrivedFrom.Inventory, slot, count);
                SystemMessages.YouAddedItemNameXItemAmountToTrade(item.ItemId, count).Send(arrivedFrom);
                SystemMessages.OpponentAddedItemNameItemAmount(arrivedFrom.PlayerData.Name, item.ItemId, count).Send(
                    arrivedFrom.Equals(Player1) ? Player2 : Player1);
                UpdateWindow();
            }
        }
Esempio n. 20
0
 public void AddQuests(Player player)
 {
     foreach (var quest in player.Quests.ToList())
     {
         AddQuest(player, quest.Value);
     }
 }
        public void AddMoney(Player arrivedFrom, long money)
        {
            lock (TradeLock)
            {
                if (IsTradeFinished())
                    return;

                if (arrivedFrom != Player1 && arrivedFrom != Player2)
                    return;

                Storage storage = arrivedFrom.Equals(Player1) ? Storage1 : Storage2;
                if (storage.Locked)
                {
                    SystemMessages.TradeListLocked.Send(arrivedFrom);
                    return;
                }

                if (!Communication.Global.StorageService.RemoveMoney(arrivedFrom, arrivedFrom.Inventory, money))
                    return;

                Communication.Global.StorageService.AddMoneys(arrivedFrom, storage, money);

                CheckLock(arrivedFrom.Equals(Player1) ? Storage2 : Storage1);
                SystemMessages.YouOfferedMoney(storage.Money).Send(arrivedFrom);
                SystemMessages.OpponentOfferedMoney(arrivedFrom.PlayerData.Name, storage.Money).Send(
                    arrivedFrom.Equals(Player1) ? Player2 : Player1);
                UpdateWindow();
            }
        }
Esempio n. 22
0
 public void AddCharacterToGuild(Player player, Guild guild)
 {
     string SQL = "UPDATE guilds SET guildmembers = ?player WHERE guildname = ?gname";
     MySqlCommand cmd = new MySqlCommand(SQL, GuildDAOConnection);
     cmd.Parameters.AddWithValue("?player", player);
     cmd.Parameters.AddWithValue("?gname", guild.GuildName);
 }
Esempio n. 23
0
        public bool AddItem(Player player, StorageType type, KeyValuePair<int, StorageItem> KeyVP)
        {
            string SQL = "INSERT INTO `inventory` "
                    + "(`accountname`, `playerid`, `itemid`, `amount`, `color`, `slot`, `storagetype`) "
                    + "VALUES(?accountname, ?pid, ?itemid, ?count, ?color, ?slot, ?type);";
            MySqlCommand cmd = new MySqlCommand(SQL, InventoryDAOConnection);
            cmd.Parameters.AddWithValue("?accountname", player.AccountName);
            cmd.Parameters.AddWithValue("?pid", player.pid);
            cmd.Parameters.AddWithValue("?itemid", KeyVP.Value.ItemId);
            cmd.Parameters.AddWithValue("?count", KeyVP.Value.Count);
            cmd.Parameters.AddWithValue("?color", KeyVP.Value.Color);
            cmd.Parameters.AddWithValue("?slot", KeyVP.Key);
            cmd.Parameters.AddWithValue("?type", type.ToString());

            try
            {
                cmd.ExecuteNonQuery();
                return true;
            }
            catch (Exception e)
            {
                Log.ErrorException("DAO: ADD ITEM ERROR!", e);
            }

            return false;
        }
Esempio n. 24
0
 public override void Init(Player player)
 {
     QuestData questData = player.Quests[Quest.QuestId];
     questData.Counters = new List<int>(Task.Targets.Count);
     for (int i = 0; i < Task.Targets.Count; i++)
         questData.Counters.Add(0);
 }
Esempio n. 25
0
        public void FinishDuel(Player winner)
        {
            if(winner.Duel == null)
                return;

            Duel d = winner.Duel;

            SendDuelEnd(d);

            SystemMessages.DuelWon.Send(winner);
            SystemMessages.DuelLost.Send(d.Initiator.Equals(winner) ? d.Initiated : winner);

            d.Initiator.Duel = null;
            d.Initiated.Duel = null;

            Communication.Global.RelationService.ResendRelation(d.Initiator);
            Communication.Global.RelationService.ResendRelation(d.Initiated);

            if(d.Initiator.Controller is BattleController)
                ((BattleController)d.Initiator.Controller).RemoveTarget(d.Initiated);
            if (d.Initiated.Controller is BattleController)
                ((BattleController)d.Initiated.Controller).RemoveTarget(d.Initiator);

            lock (DuelsLock)
                Duels.Remove(d);
            Communication.Global.ActionEngine.RemoveRequest(d.Request);
        }
Esempio n. 26
0
        public void SaveSkill(Player player, int SkillId)
        {
            string cmdString = "SELECT * FROM skills WHERE SkillId=?sid AND PlayerId=?pid";
            MySqlCommand command = new MySqlCommand(cmdString, SkillsDAOConnection);
            command.Parameters.AddWithValue("?sid", SkillId);
            command.Parameters.AddWithValue("?pid", player.Id);
            MySqlDataReader SkillDAOreader = command.ExecuteReader();
            bool isExists = SkillDAOreader.HasRows;
            SkillDAOreader.Close();

            if (!isExists)
            {
                cmdString = "INSERT INTO skills (PlayerId, SkillId) VALUES (?pid, ?sid)";
                command = new MySqlCommand(cmdString, SkillsDAOConnection);
                command.Parameters.AddWithValue("?sid", SkillId);
                command.Parameters.AddWithValue("?pid", player.Id);

                try
                {
                    command.ExecuteNonQuery();
                }
                catch (MySqlException ex)
                {
                    Logger.WriteLine(LogState.Exception, "SaveQuest Error"+ ex.Message);
                }
            }
        }
        public void Start(Player player)
        {
            if(!CanPlayerUseGather())
                return;

            StartGathering();
        }
Esempio n. 28
0
        public static bool TryPutCampfire(Player player, WorldPosition position)
        {
            bool putCampfire = true;

            player.Instance.Campfires.Each(campfire =>
            {
                if (campfire.Position.DistanceTo(player.Position) < 1000)
                    putCampfire = false;
            });

            if (!putCampfire)
            {
                SystemMessages.TheresAnotherCampfireNearHere.Send(player);
                return false;
            }

            player.Instance.Campfires.Add(new Campfire
            {
                Instance = player.Instance,
                Type = 1,
                Status = 0,
                Position =
                    Geom.GetNormal(position.Heading).Multiple(50).Add(player.Position)
                    .ToWorldPosition(),
                DespawnUts = Funcs.GetCurrentMilliseconds() + 1200000, //20 minutes
            });

            return true;
        }
Esempio n. 29
0
        public void Lock(Player player)
        {
            if (!(player.Controller is PlayerTradeController))
                return;

            ((PlayerTradeController)player.Controller).Lock(player);
        }
Esempio n. 30
0
        public static bool IsVisible(Player player, Creature creature)
        {
            if (creature is Player && !Communication.Global.PlayerService.IsPlayerOnline((Player)creature))
                return false;

            if (creature == null)
                return false;

            if (!(creature is Item) && !(creature is Gather) && !(creature is Campfire)
                && creature.LifeStats.IsDead())
                return false;

            if (creature is Gather && ((Gather)creature).CurrentGatherCounter <= 0)
                return false;

            double distance = player.Position.DistanceTo(creature.Position);
            if (distance > VisibleDistance)
                return false;

            if (creature is Npc && distance < 75)
                creature.Position.Z = player.Position.Z + 25;

            PlayerLogic.DistanceToCreatureRecalculated(player, creature, distance);

            return true;
        }
Esempio n. 31
0
 public CreatureBaseStats GetBaseStats(Data.Structures.Player.Player player)
 {
     return(PlayerStats[player.PlayerData.Class][player.GetLevel()]);
 }