예제 #1
0
        public static void CheckResource(int index, int x, int y)
        {
            int  Resource_num;
            byte ResourceType;
            int  Resource_index;
            int  rX;
            int  rY;
            int  Damage;

            if (modTypes.Map[S_Players.GetPlayerMap(index)].Tile[x, y].Type == (byte)Enums.TileType.Resource)
            {
                Resource_num   = 0;
                Resource_index = modTypes.Map[S_Players.GetPlayerMap(index)].Tile[x, y].Data1;
                ResourceType   = (byte)Types.Resource[Resource_index].ResourceType;
                var loopTo = ResourceCache[S_Players.GetPlayerMap(index)].ResourceCount;

                // Get the cache number
                for (var i = 0; i <= loopTo; i++)
                {
                    if (ResourceCache[S_Players.GetPlayerMap(index)].ResourceData[i].X == x)
                    {
                        if (ResourceCache[S_Players.GetPlayerMap(index)].ResourceData[i].Y == y)
                        {
                            Resource_num = i;
                        }
                    }
                }

                if (Resource_num > 0)
                {
                    if (S_Players.GetPlayerEquipment(index, Enums.EquipmentType.Weapon) > 0 || Types.Resource[Resource_index].ToolRequired == 0)
                    {
                        if (Types.Item[S_Players.GetPlayerEquipment(index, Enums.EquipmentType.Weapon)].Data3 == Types.Resource[Resource_index].ToolRequired)
                        {
                            // inv space?
                            if (Types.Resource[Resource_index].ItemReward > 0)
                            {
                                if (S_Players.FindOpenInvSlot(index, Types.Resource[Resource_index].ItemReward) == 0)
                                {
                                    S_NetworkSend.PlayerMsg(index, "You have no inventory space.", (int)Enums.ColorType.Yellow);
                                    return;
                                }
                            }

                            // required lvl?
                            if (Types.Resource[Resource_index].LvlRequired > GetPlayerGatherSkillLvl(index, ResourceType))
                            {
                                S_NetworkSend.PlayerMsg(index, "Your level is too low!", (int)Enums.ColorType.Yellow);
                                return;
                            }

                            // check if already cut down
                            if (ResourceCache[S_Players.GetPlayerMap(index)].ResourceData[Resource_num].ResourceState == 0)
                            {
                                rX = ResourceCache[S_Players.GetPlayerMap(index)].ResourceData[Resource_num].X;
                                rY = ResourceCache[S_Players.GetPlayerMap(index)].ResourceData[Resource_num].Y;

                                if (Types.Resource[Resource_index].ToolRequired == 0)
                                {
                                    Damage = 1 * GetPlayerGatherSkillLvl(index, ResourceType);
                                }
                                else
                                {
                                    Damage = Types.Item[S_Players.GetPlayerEquipment(index, Enums.EquipmentType.Weapon)].Data2;
                                }

                                // check if damage is more than health
                                if (Damage > 0)
                                {
                                    // cut it down!
                                    if (ResourceCache[S_Players.GetPlayerMap(index)].ResourceData[Resource_num].CurHealth - Damage <= 0)
                                    {
                                        ResourceCache[S_Players.GetPlayerMap(index)].ResourceData[Resource_num].ResourceState = 1; // Cut
                                        ResourceCache[S_Players.GetPlayerMap(index)].ResourceData[Resource_num].ResourceTimer = S_General.GetTimeMs();
                                        SendResourceCacheToMap(S_Players.GetPlayerMap(index), Resource_num);
                                        S_NetworkSend.SendActionMsg(S_Players.GetPlayerMap(index), Types.Resource[Resource_index].SuccessMessage.Trim(), (int)Enums.ColorType.BrightGreen, 1, (S_Players.GetPlayerX(index) * 32), (S_Players.GetPlayerY(index) * 32));
                                        S_Players.GiveInvItem(index, Types.Resource[Resource_index].ItemReward, 1);
                                        S_Animations.SendAnimation(S_Players.GetPlayerMap(index), Types.Resource[Resource_index].Animation, rX, rY);
                                        SetPlayerGatherSkillExp(index, ResourceType, GetPlayerGatherSkillExp(index, ResourceType) + Types.Resource[Resource_index].ExpReward);
                                        // send msg
                                        S_NetworkSend.PlayerMsg(index, string.Format("Your {0} has earned {1} experience. ({2}/{3})", GetResourceSkillName((Enums.ResourceSkills)ResourceType), Types.Resource[Resource_index].ExpReward, GetPlayerGatherSkillExp(index, ResourceType), GetPlayerGatherSkillMaxExp(index, ResourceType)), (int)Enums.ColorType.BrightGreen);
                                        S_NetworkSend.SendPlayerData(index);

                                        CheckResourceLevelUp(index, ResourceType);
                                    }
                                    else
                                    {
                                        // just do the damage
                                        ResourceCache[S_Players.GetPlayerMap(index)].ResourceData[Resource_num].CurHealth = (byte)(ResourceCache[S_Players.GetPlayerMap(index)].ResourceData[Resource_num].CurHealth - Damage);
                                        S_NetworkSend.SendActionMsg(S_Players.GetPlayerMap(index), "-" + Damage, (int)Enums.ColorType.BrightRed, 1, (rX * 32), (rY * 32));
                                        S_Animations.SendAnimation(S_Players.GetPlayerMap(index), Types.Resource[Resource_index].Animation, rX, rY);
                                    }
                                    S_Quest.CheckTasks(index, (int)Enums.QuestType.Gather, Resource_index);
                                }
                                else
                                {
                                    // too weak
                                    S_NetworkSend.SendActionMsg(S_Players.GetPlayerMap(index), "Miss!", (int)Enums.ColorType.BrightRed, 1, (rX * 32), (rY * 32));
                                }
                            }
                            else
                            {
                                S_NetworkSend.SendActionMsg(S_Players.GetPlayerMap(index), Types.Resource[Resource_index].EmptyMessage.Trim(), (int)Enums.ColorType.BrightRed, 1, (S_Players.GetPlayerX(index) * 32), (S_Players.GetPlayerY(index) * 32));
                            }
                        }
                        else
                        {
                            S_NetworkSend.PlayerMsg(index, "You have the wrong type of tool equiped.", (int)Enums.ColorType.Yellow);
                        }
                    }
                    else
                    {
                        S_NetworkSend.PlayerMsg(index, "You need a tool to gather this resource.", (int)Enums.ColorType.Yellow);
                    }
                }
            }
        }