Example #1
0
 public virtual void Release()
 {
     Creature = null;
     Npc = null;
     Player = null;
     Random = null;
 }
Example #2
0
        public void RemoveItem(Player player, int slot, int count)
        {
            if (!(player.Controller is PlayerTradeController))
                return;

            ((PlayerTradeController)player.Controller).RemoveItem(player, slot, count);
        }
Example #3
0
        public void Cancel(Player player)
        {
            if (!(player.Controller is PlayerTradeController))
                return;

            ((PlayerTradeController)player.Controller).Cancel(player);
        }
Example #4
0
        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();
            }
        }
Example #5
0
        public void ResendQuestData(Player player)
        {
            List<int> completed = new List<int>();

            foreach (var questData in player.Quests.Values)
            {
                if (questData.Status != QuestStatus.Complete)
                {
                    new SpQuest(questData,
                                null,
                                1,
                                Quests[questData.QuestId].GetNowStep(player).IsCountersComplete(player))
                        .Send(player.Connection);

                    continue;
                }

                if (Data.Data.Quests[questData.QuestId].Type != QuestType.Mission)
                    continue;
                
                completed.Add(questData.QuestId);
            }

            PlayerLevelUp(player);

            new SpComplitedQuests(completed).Send(player.Connection);
        }
Example #6
0
        public override List<int> GetParticipantVillagers(Player player)
        {
            if (!IsCountersComplete(player))
                return new List<int>();

            return new List<int> {Task.DeliverToFullId};
        }
Example #7
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);
                }
            }
        }
Example #8
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;
        }
Example #9
0
        public void AddStartItemsToPlayer(Player player)
        {
            player.Inventory.Items.Add(20, new StorageItem {ItemId = 125, Amount = 5});
            player.Inventory.Items.Add(21, new StorageItem { ItemId = 8007, Amount = 3 });

            switch (player.PlayerData.Class)
            {
                case PlayerClass.Warrior:
                    player.Inventory.Items.Add(1, new StorageItem { ItemId = 10001, Amount = 1 });
                    player.Inventory.Items.Add(3, new StorageItem { ItemId = 15004, Amount = 1 });
                    player.Inventory.Items.Add(4, new StorageItem { ItemId = 15005, Amount = 1 });
                    player.Inventory.Items.Add(5, new StorageItem { ItemId = 15006, Amount = 1 });
                    break;
                case PlayerClass.Archer:
                    player.Inventory.Items.Add(1, new StorageItem { ItemId = 10006, Amount = 1 });
                    player.Inventory.Items.Add(3, new StorageItem { ItemId = 15004, Amount = 1 });
                    player.Inventory.Items.Add(4, new StorageItem { ItemId = 15005, Amount = 1 });
                    player.Inventory.Items.Add(5, new StorageItem { ItemId = 15006, Amount = 1 });
                    break;
                case PlayerClass.Slayer:
                    player.Inventory.Items.Add(1, new StorageItem { ItemId = 10003, Amount = 1 });
                    player.Inventory.Items.Add(3, new StorageItem { ItemId = 15004, Amount = 1 });
                    player.Inventory.Items.Add(4, new StorageItem { ItemId = 15005, Amount = 1 });
                    player.Inventory.Items.Add(5, new StorageItem { ItemId = 15006, Amount = 1 });
                    break;
                case PlayerClass.Berserker:
                    player.Inventory.Items.Add(1, new StorageItem { ItemId = 10004, Amount = 1 });
                    player.Inventory.Items.Add(3, new StorageItem { ItemId = 15001, Amount = 1 });
                    player.Inventory.Items.Add(4, new StorageItem { ItemId = 15002, Amount = 1 });
                    player.Inventory.Items.Add(5, new StorageItem { ItemId = 15003, Amount = 1 });
                    break;
                case PlayerClass.Lancer:
                    player.Inventory.Items.Add(1, new StorageItem { ItemId = 10002, Amount = 1 });
                    player.Inventory.Items.Add(3, new StorageItem { ItemId = 15001, Amount = 1 });
                    player.Inventory.Items.Add(4, new StorageItem { ItemId = 15002, Amount = 1 });
                    player.Inventory.Items.Add(5, new StorageItem { ItemId = 15003, Amount = 1 });
                    break;

                case PlayerClass.Sorcerer:
                    player.Inventory.Items.Add(1, new StorageItem { ItemId = 10005, Amount = 1 });
                    player.Inventory.Items.Add(3, new StorageItem { ItemId = 15007, Amount = 1 });
                    player.Inventory.Items.Add(4, new StorageItem { ItemId = 15008, Amount = 1 });
                    player.Inventory.Items.Add(5, new StorageItem { ItemId = 15009, Amount = 1 });
                    break;

                case PlayerClass.Mystic:
                    player.Inventory.Items.Add(1, new StorageItem { ItemId = 10008, Amount = 1 });
                    player.Inventory.Items.Add(3, new StorageItem { ItemId = 15007, Amount = 1 });
                    player.Inventory.Items.Add(4, new StorageItem { ItemId = 15008, Amount = 1 });
                    player.Inventory.Items.Add(5, new StorageItem { ItemId = 15009, Amount = 1 });
                    break;

                case PlayerClass.Priest:
                    player.Inventory.Items.Add(1, new StorageItem { ItemId = 10007, Amount = 1 });
                    player.Inventory.Items.Add(3, new StorageItem { ItemId = 15007, Amount = 1 });
                    player.Inventory.Items.Add(4, new StorageItem { ItemId = 15008, Amount = 1 });
                    player.Inventory.Items.Add(5, new StorageItem { ItemId = 15009, Amount = 1 });
                    break;
            }
        }
Example #10
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);
        }
Example #11
0
 public void AddQuests(Player player)
 {
     foreach (var quest in player.Quests.ToList())
     {
         AddQuest(player, quest.Value);
     }
 }
Example #12
0
        public void ProcessDamage(Player player)
        {
            if(player.Duel == null)
                return;

            player.Duel.LastKickUtc = RandomUtilities.GetCurrentMilliseconds();
        }
Example #13
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)
            {
                Logger.WriteLine(LogState.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);
            }
        }
Example #14
0
        public void AddNewParty(Player inviter, List<Player> invitedPlayers)
        {
            AddNewParty(inviter, invitedPlayers[0]);

            for (int i = 1; i < invitedPlayers.Count; i++)
                AddPlayerToParty(invitedPlayers[i], ref inviter.Party);
        }
Example #15
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, ?amount, ?color, ?slot, ?type);";
            MySqlCommand cmd = new MySqlCommand(SQL, InventoryDAOConnection);
            cmd.Parameters.AddWithValue("?accountname", player.AccountName);
            cmd.Parameters.AddWithValue("?pid", player.Id);
            cmd.Parameters.AddWithValue("?itemid", KeyVP.Value.ItemId);
            cmd.Parameters.AddWithValue("?amount", KeyVP.Value.Amount);
            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 ex)
            {
                Logger.WriteLine(LogState.Exception, "DAO: ADD ITEM ERROR!"+  ex.Message);
            }

            return false;
        }
Example #16
0
 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);
 }
Example #17
0
        public Storage LoadStorage(Player player, StorageType type)
        {
            string SQL = "SELECT * FROM `inventory` WHERE "
                + "`playerid` = ?pid AND `storagetype` = ?type";
            MySqlCommand cmd = new MySqlCommand(SQL, InventoryDAOConnection);
            cmd.Parameters.AddWithValue("?pid", player.Id);
            cmd.Parameters.AddWithValue("?type", type.ToString());
            MySqlDataReader LoadStorageReader = cmd.ExecuteReader();

            var storage = new Storage { StorageType = StorageType.Inventory };
            if (LoadStorageReader.HasRows)
            {
                while (LoadStorageReader.Read())
                {
                    if (LoadStorageReader.GetInt32(2) != 20000000)
                    {
                        StorageItem item = new StorageItem()
                        {
                            ItemId = LoadStorageReader.GetInt32(2),
                            Amount = LoadStorageReader.GetInt32(3),
                            Color = LoadStorageReader.GetInt32(4),
                        };

                        storage.Items.Add(LoadStorageReader.GetInt32(5), item);
                    }
                    else
                    {
                        storage.Money = LoadStorageReader.GetInt32(3);
                    }
                }
            }
            LoadStorageReader.Close();

            return storage;
        }
Example #18
0
        public void TrySetDefaultController(Player player)
        {
            if (player.Controller is DefaultController)
                return;

            SetController(player, new DefaultController());
        }
Example #19
0
        public override List<int> GetParticipantMonsters(Player player)
        {
            if (IsCountersComplete(player))
                return new List<int>();

            return new List<int>(Task.DroppedFrom);
        }
Example #20
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;
        }
Example #21
0
 public void SaveSkills(Player player)
 {
     foreach (var skill in player.Skills)
     {
         SaveSkill(player, skill);
     }
 }
Example #22
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;
        }
Example #23
0
        public void AddMemberToGuild(Player player, Guild guild, Player inviter = null)
        {
            if (guild == null || player == null)
                return;

            if(guild.GuildMembers != null && guild.GuildMembers.Count > 30)
                return;

            lock (guild.MembersLock)
            {
                if (guild.GuildMembers == null || guild.GuildMembers.Count == 0)
                    guild.GuildMembers = new Dictionary<Player, int> {{player, 1}};
                else
                    guild.GuildMembers.Add(player, 2);
            }

            AddHistoryEvent(guild,
                            new HistoryEvent
                                {
                                    Args = GuildHistoryStrings.UserXInvitedUserY(player.PlayerData.Name)
                                        /* TODO: 
                                         * inviter != null
                                            ? GuildHistoryStrings.UserXInvitedUserY(player.PlayerData.Name)
                                            : GuildHistoryStrings.GuildCreate(player.PlayerData.Name)*/
                                });

            player.Guild = guild;

            Communication.Global.VisibleService.Send(player,
                                                     new SpCharacterGuildInfo(player, guild.GuildName, "Recruit"));

            Communication.Global.RelationService.ResendRelation(player);
        }
Example #24
0
 public SpPegasusFlight(Player player, int teleportId, int state, int time)
 {
     Player = player;
     TeleportId = teleportId;
     State = state;
     Time = time;
 }
Example #25
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);
 }
Example #26
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
        }
Example #27
0
        public void Lock(Player player)
        {
            if (!(player.Controller is PlayerTradeController))
                return;

            ((PlayerTradeController)player.Controller).Lock(player);
        }
Example #28
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);
 }
Example #29
0
        public void Start(Player player)
        {
            if(!CanPlayerUseGather())
                return;

            StartGathering();
        }
Example #30
0
 public SpTradeHideWindow(Player player1, Player player2, int tradeId, int type = 1)
 {
     Player1 = player1;
     Player2 = player2;
     TradeId = tradeId;
     Type = type;
 }