Exemplo n.º 1
0
    private void SetTreasure()
    {
        Vector2 islandCenter        = new Vector2(offset.x, offset.z);
        Vector2 treasureMaxDistance = islandCenter - new Vector2(MIN_DISTANCE_TO_BORDER, MIN_DISTANCE_TO_BORDER);

        for (int i = 0; i < treasureCount; i++)
        {
            ChestInfo chestInfo      = new ChestInfo();
            bool      randomPosition = ChestAt(i, out chestInfo.chest);
            chestInfo.moveChest = randomPosition;
            chestInfo.markChest = chestInfo.chest == null || chestInfo.chest.isMarked;
            Vector2 treasurePosition = Vector2.zero;
            Vector2 locationProgress = Random.insideUnitCircle;
            if (randomPosition)
            {
                treasurePosition = locationProgress * treasureMaxDistance;

                treasurePosition = new Vector2(Mathf.Round(treasurePosition.x), Mathf.Round(treasurePosition.y));
                locationProgress = LocalPosToProgress(treasurePosition + islandCenter);
            }
            else
            {
                treasurePosition = TransformToLocal2DPosition(chestInfo.chest.transform.position);
                locationProgress = LocalPosToProgress(treasurePosition + islandCenter);
            }

            chestInfo.localPosition    = treasurePosition;
            chestInfo.locationProgress = locationProgress;
            //treasureProgressLocations.Add();
            //treasurePositions.Add(treasurePosition);
            chests.Add(chestInfo);
        }
    }
Exemplo n.º 2
0
 public static void AddToVanillaChest(ChestInfo item, int chestFrame, int index)
 {
     chestFrame *= 36;
     for (int chestIndex = 0; chestIndex < Main.chest.Length; chestIndex++)
     {
         Chest chest = Main.chest[chestIndex];
         if (chest != null && Main.tile[chest.x, chest.y].type == TileID.Containers && Main.tile[chest.x, chest.y].frameX == chestFrame)
         {
             PlaceChestItems(item.ToList(), chest, index);
         }
     }
 }
Exemplo n.º 3
0
    public void BattleResult(WBattleResult result)
    {
        ChestInfo chestInfo = null;

        if (result.reward.chest_info != null)
        {
            chestInfo = ChestInfoHelper.GetChestInfo(result.reward.chest_info);
        }

        RewardData rewData = new RewardData(result.reward.coin,
                                            result.reward.trophy,
                                            chestInfo);

        BattleResultData btlResultData = new BattleResultData(result.total_score, result.current_rank,
                                                              result.previous_rank, result.victorious, rewData);

        if (Event_BattleFinish != null)
        {
            Event_BattleFinish(btlResultData, MakeTroopCooldownList(result.cooldown_data), result.connection_lost);
        }
    }
Exemplo n.º 4
0
 public RewardData(int coin, int trophy, ChestInfo chestInfo)
 {
     this.coin      = coin;
     this.trophy    = trophy;
     this.chestInfo = chestInfo;
 }
        private bool RequestChestOpen(ref BinaryReader reader, int playerNumber)
        {
            if (!ServerSideCharacter.Config.EnableChestProtection)
            {
                return(false);
            }
            if (Main.netMode == 2)
            {
                int                  x       = reader.ReadInt16();
                int                  y       = reader.ReadInt16();
                int                  id      = Chest.FindChest(x, y);
                Player               player  = Main.player[playerNumber];
                ServerPlayer         sPlayer = player.GetServerPlayer();
                ChestManager.Pending pending = ServerSideCharacter.ChestManager.GetPendings(sPlayer);
                switch (pending)
                {
                case ChestManager.Pending.AddFriend:
                    if (ServerSideCharacter.ChestManager.IsOwner(id, sPlayer))
                    {
                        ServerPlayer friend = ServerSideCharacter.ChestManager.GetFriendP(sPlayer);
                        ServerSideCharacter.ChestManager.AddFriend(id, friend);
                        sPlayer.SendSuccessInfo($"{friend.Name} can open this chest now");
                    }
                    else
                    {
                        sPlayer.SendErrorInfo("You are not the owner of this chest");
                    }
                    break;

                case ChestManager.Pending.RemoveFriend:
                    if (ServerSideCharacter.ChestManager.IsOwner(id, sPlayer))
                    {
                        ServerPlayer friend = ServerSideCharacter.ChestManager.GetFriendP(sPlayer);
                        ServerSideCharacter.ChestManager.RemoveFriend(id, friend);
                        sPlayer.SendSuccessInfo($"{friend.Name} can't open this chest now");
                    }
                    else
                    {
                        sPlayer.SendErrorInfo("You are not the owner of this chest");
                    }
                    break;

                case ChestManager.Pending.Public:
                    if (ServerSideCharacter.ChestManager.IsOwner(id, sPlayer))
                    {
                        if (!ServerSideCharacter.ChestManager.IsPublic(id))
                        {
                            ServerSideCharacter.ChestManager.SetOwner(id, sPlayer.UUID, true);
                            sPlayer.SendSuccessInfo("This chest is now Public");
                        }
                        else
                        {
                            sPlayer.SendErrorInfo("This chest is already public");
                        }
                    }
                    else
                    {
                        sPlayer.SendErrorInfo("You are not the owner of this chest");
                    }
                    break;

                case ChestManager.Pending.UnPublic:
                    if (ServerSideCharacter.ChestManager.IsOwner(id, sPlayer))
                    {
                        if (ServerSideCharacter.ChestManager.IsPublic(id))
                        {
                            ServerSideCharacter.ChestManager.SetOwner(id, sPlayer.UUID, false);
                            sPlayer.SendSuccessInfo("This chest is not Public anymore");
                        }
                        else
                        {
                            sPlayer.SendErrorInfo("This chest is not public");
                        }
                    }
                    else
                    {
                        sPlayer.SendErrorInfo("You are not the owner of this chest");
                    }
                    break;

                case ChestManager.Pending.Protect:
                    if (ServerSideCharacter.ChestManager.IsNull(id))
                    {
                        ServerSideCharacter.ChestManager.SetOwner(id, sPlayer.UUID, false);
                        sPlayer.SendSuccessInfo("You now own this chest");
                    }
                    else if (ServerSideCharacter.ChestManager.IsOwner(id, sPlayer))
                    {
                        sPlayer.SendErrorInfo("You already protected this chest");
                    }
                    else
                    {
                        sPlayer.SendErrorInfo("This chest as already been protected by other player");
                    }
                    break;

                case ChestManager.Pending.DeProtect:
                    if (ServerSideCharacter.ChestManager.IsOwner(id, sPlayer))
                    {
                        ServerSideCharacter.ChestManager.SetOwner(id, -1, false);
                        sPlayer.SendSuccessInfo("This chest is no longer yours");
                    }
                    else if (ServerSideCharacter.ChestManager.IsNull(id))
                    {
                        sPlayer.SendErrorInfo("This chest don't have a owner");
                    }
                    else
                    {
                        sPlayer.SendErrorInfo("You are not the owner of this chest");
                    }
                    break;

                case ChestManager.Pending.Info:
                    if (ServerSideCharacter.ChestManager.IsOwner(id, sPlayer))
                    {
                        ChestInfo     chest = ServerSideCharacter.ChestManager.ChestInfo[id];
                        StringBuilder info  = new StringBuilder();
                        if (sPlayer.PermissionGroup.HasPermission("chest"))
                        {
                            info.AppendLine($"Owner: {ServerPlayer.FindPlayer(chest.OwnerID).Name}");                                     //For Admins
                        }
                        info.AppendLine($"Public Chest: {chest.IsPublic.ToString().ToUpper()}");
                        info.AppendLine($"Friends ({chest.Friends.Count.ToString()}): {string.Join(", ", chest.Friends.ToArray().Take(10).Select(uuid => ServerPlayer.FindPlayer(uuid).Name))}");
                        sPlayer.SendInfo(info.ToString());
                    }
                    else if (ServerSideCharacter.ChestManager.IsNull(id))
                    {
                        sPlayer.SendErrorInfo("This chest don't have a owner");
                    }
                    else
                    {
                        sPlayer.SendErrorInfo("You are not the owner of this chest");
                    }
                    break;

                default:
                    if (ServerSideCharacter.ChestManager.IsNull(id))
                    {
                        if (ServerSideCharacter.Config.AutoProtectChests)
                        {
                            ServerSideCharacter.ChestManager.SetOwner(id, sPlayer.UUID, false);
                            sPlayer.SendSuccessInfo("You now own this chest");
                        }
                        else
                        {
                            sPlayer.SendErrorInfo("Use '/chest protect' to become the owner of this chest");
                        }
                        return(false);
                    }
                    else if (ServerSideCharacter.ChestManager.CanOpen(id, sPlayer))
                    {
                        return(false);
                    }
                    else
                    {
                        sPlayer.SendErrorInfo("You cannot open this chest");
                    }
                    break;
                }
                ServerSideCharacter.ChestManager.RemovePending(sPlayer, pending);
            }
            return(true);
        }