Ejemplo n.º 1
0
        private void ValSpecial(int x, int y)
        {
            Tile curTile = Tiles[x, y];

            //validate chest entry exists
            if (Tile.IsChest(curTile.Type))
            {
                if (IsAnchor(x, y) && GetChestAtTile(x, y, true) == null)
                {
                    Chests.Add(new Chest(x, y));
                }
            }
            //validate sign entry exists
            else if (Tile.IsSign(curTile.Type))
            {
                if (IsAnchor(x, y) && GetSignAtTile(x, y, true) == null)
                {
                    Signs.Add(new Sign(x, y, string.Empty));
                }
            }
            //validate TileEntity
            else if (Tile.IsTileEntity(curTile.Type))
            {
                if (IsAnchor(x, y) && GetTileEntityAtTile(x, y, true) == null)
                {
                    var TE = TileEntity.CreateForTile(curTile, x, y, TileEntities.Count);
                    TileEntities.Add(TE);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handle the click event if it was on the fridge icon.
        /// </summary>
        /// <param name="cursor">The current cursor position.</param>
        public void HandleClick(ICursorPosition cursor)
        {
            var chest = GetOpenChest();

            if (chest == null)
            {
                return;
            }

            var screenPixels = cursor.ScreenPixels;

            if (!_fridgeSelected.containsPoint((int)screenPixels.X, (int)screenPixels.Y))
            {
                return;
            }

            Game1.playSound("smallSelect");

            if (Chests.Contains(chest))
            {
                Chests.Remove(chest);
            }
            else
            {
                Chests.Add(chest);
            }
        }
Ejemplo n.º 3
0
        public static void Initialize()
        {
            // Initialize our stuff.
            CSV.Initialize();
            Game_Events.Initialize();
            Deck.Initialize();
            Files.Cards.Initialize();
            Fingerprint.Initialize();

            Arenas.Initialize();
            Rarities.Initialize();
            Logic.Structure.Game.Cards.Initialize();
            Chests.Initialize();

            ResourcesManager.Initialize();
            ObjectManager.Initialize();

            Logger.Initialize();
            ExceptionLogger.Initialize();

            Gateway.Initialize();
            Timers.Initialize();
            Timers.Run();

            // Start listening since we're done initializing.
            Gateway.Listen();
            if (Constants.UseDiscord)
            {
                Client.Initialize();
            }
            Events = new EventsHandler();
        }
Ejemplo n.º 4
0
 public World()
 {
     NPCs.Clear();
     Signs.Clear();
     Chests.Clear();
     CharacterNames.Clear();
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Draw the fridge button
        /// </summary>
        public void DrawFridge()
        {
            var openChest = GetOpenChest();

            if (openChest == null)
            {
                return;
            }

            var farmHouse = Game1.getLocationFromName("farmHouse") as FarmHouse;

            if (openChest == farmHouse?.fridge.Value || Game1.activeClickableMenu == null ||
                !openChest.playerChest.Value)
            {
                return;
            }

            UpdatePos();
            if (Chests.Contains(openChest))
            {
                _fridgeSelected.draw(Game1.spriteBatch);
            }
            else
            {
                _fridgeDeselected.draw(Game1.spriteBatch);
            }

            Game1.spriteBatch.Draw(Game1.mouseCursors, new Vector2(Game1.getOldMouseX(), Game1.getOldMouseY()),
                                   Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, 0, 16, 16), Color.White, 0f, Vector2.Zero,
                                   4f + Game1.dialogueButtonScale / 150f, SpriteEffects.None, 0);
        }
Ejemplo n.º 6
0
        public void Validate()
        {
            for (int x = 0; x < TilesWide; x++)
            {
                OnProgressChanged(this, new ProgressChangedEventArgs((int)(x / (float)TilesWide * 100.0), "Validating World..."));

                for (int y = 0; y < TilesHigh; y++)
                {
                    var curTile = Tiles[x, y];

                    if (curTile.Type == 127)
                    {
                        curTile.IsActive = false;
                    }

                    // TODO: Let Validate handle these
                    //validate chest entry exists
                    if (curTile.Type == 21)
                    {
                        if (GetChestAtTile(x, y) == null)
                        {
                            Chests.Add(new Chest(x, y));
                        }
                    }
                    //validate sign entry exists
                    else if (curTile.Type == 55 || curTile.Type == 85)
                    {
                        if (GetSignAtTile(x, y) == null)
                        {
                            Signs.Add(new Sign(x, y, string.Empty));
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
 public World()
 {
     NPCs.Clear();
     Signs.Clear();
     Chests.Clear();
     CharacterNames.Clear();
     TileFrameImportant = SettingsTileFrameImportant.ToArray(); // clone for "new" world. Loaded worlds will replace this with file data
 }
Ejemplo n.º 8
0
        public void ClearWorld()
        {
            _tiles = new Tile[Header.WorldBounds.W, Header.WorldBounds.H];

            Chests.Clear();
            Signs.Clear();
            Npcs.Clear();
        }
Ejemplo n.º 9
0
 public override void PickedChest(Character character, Collider2D chestCol)
 {
     chestCol.enabled = false;
     Debug.Log("Removing: " + chestCol.GetComponent <SpawnedObject>().Id);
     Chests.Remove(chestCol.GetComponent <SpawnedObject>().Id);
     iTween.ScaleTo(chestCol.gameObject, iTween.Hash("scale", Vector3.zero, "time", 1f));
     Destroy(chestCol.gameObject, 1f);
     character.Score++;
 }
Ejemplo n.º 10
0
 private void CollectChestIfStandingOnIt()
 {
     if (Chests.Contains(State.Position))
     {
         State.Scores++;
         VisitedChests.Add(State.Position);
         Chests.Remove(State.Position);
     }
 }
Ejemplo n.º 11
0
        public void AddChest(KhaldunChest Chest)
        {
            if (Chests == null)
            {
                Chests = new List <KhaldunChest>();
            }

            if (!Chests.Contains(Chest))
            {
                Chests.Add(Chest);
            }
        }
Ejemplo n.º 12
0
        private void LoadChest(Object gameLocationObject, FarmHouse farmHouse)
        {
            if (!(gameLocationObject is Chest chest))
            {
                return;
            }

            if (chest.fridge.Value && chest != farmHouse?.fridge.Value)
            {
                Chests.Add(chest);
                chest.fridge.Value = false;
            }
        }
Ejemplo n.º 13
0
        public void ValSpecial(int x, int y)
        {
            Tile curTile = Tiles[x, y];

            //validate chest entry exists
            if (Tile.IsChest(curTile.Type))
            {
                if (GetChestAtTile(x, y) == null)
                {
                    Chests.Add(new Chest(x, y));
                }
            }
            //validate sign entry exists
            else if (Tile.IsSign(curTile.Type))
            {
                if (GetSignAtTile(x, y) == null)
                {
                    Signs.Add(new Sign(x, y, string.Empty));
                }
            }
            //validate TileEntity
            else if (Tile.IsTileEntity(curTile.Type))
            {
                if (GetTileEntityAtTile(x, y) == null)
                {
                    TileEntity TE = new TileEntity();
                    TE.PosX = (short)x;
                    TE.PosY = (short)y;
                    TE.Id   = TileEntities.Count;
                    if (curTile.Type == (int)TileType.Dummy)
                    {
                        TE.Type = 0;
                        TE.Npc  = -1;
                    }
                    else if (curTile.Type == (int)TileType.ItemFrame)
                    {
                        TE.Type      = 1;
                        TE.NetId     = 0;
                        TE.Prefix    = 0;
                        TE.StackSize = 0;
                    }
                    else
                    {
                        TE.Type       = 2;
                        TE.On         = false;
                        TE.LogicCheck = (byte)(curTile.V / 18 + 1);
                    }
                    TileEntities.Add(TE);
                }
            }
        }
Ejemplo n.º 14
0
 public void LoadAll()
 {
     Floors.LoadAll();
     Items.LoadAll();
     Creatures.LoadAll();
     Templates.LoadAll();
     Animations.LoadAll();
     Heads.LoadAll();
     Chests.LoadAll();
     Legs.LoadAll();
     Arms.LoadAll();
     Weapons.LoadAll();
     Shields.LoadAll();
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Load all fridges.
        /// </summary>
        public void AfterLoad()
        {
            //
            Chests.Clear();
            var farmHouse = Game1.getLocationFromName("farmHouse") as FarmHouse;

            foreach (var gameLocation in GetLocations())
            {
                foreach (var gameLocationObject in gameLocation.objects.Values)
                {
                    LoadChest(gameLocationObject, farmHouse);
                }
            }
        }
    /// <summary>
    /// Se ejecuta cuando un personaje coge un cofre
    /// </summary>
    /// <param name="character">Character que ha cogido el cofre.</param>
    /// <param name="chestCol">Collider del cofre.</param>
    public override void PickedChest(Character character, Collider2D chestCol)
    {
        chestCol.enabled = false;
        var chestId = chestCol.GetComponent <SpawnedObject>().Id;

        iTween.ScaleTo(chestCol.gameObject, iTween.Hash("scale", Vector3.zero, "time", 1f));
        Chests.Remove(chestId);
        Destroy(chestCol.gameObject, 1f);
        var chestRequest = new ChestData {
            chestId  = chestId,
            playerId = _playerId
        };

        _client.Send(chestRequest.ToJson(), TAPNet.DATAGRAM_RELIABLE);
    }
Ejemplo n.º 17
0
        public void RemoveChest(KhaldunChest Chest)
        {
            if (Chests != null)
            {
                if (Chests.Contains(Chest))
                {
                    Chests.Remove(Chest);
                }

                if (TreasuresOfKhaldunEvent.Instance.Running && Chests.Count < ChestCount)
                {
                    Timer.DelayCall(TimeSpan.FromSeconds(Utility.RandomMinMax(30, 60)), () =>
                    {
                        CreateChests(1);
                    });
                }
            }
        }
Ejemplo n.º 18
0
        public void RemoveChest(KhaldunChest Chest)
        {
            if (Chests != null)
            {
                if (Chests.Contains(Chest))
                {
                    Chests.Remove(Chest);
                }

                if (PointsSystem.TreasuresOfDoom.InSeason && Chests.Count < ChestCount)
                {
                    Timer.DelayCall(TimeSpan.FromSeconds(Utility.RandomMinMax(30, 60)), () =>
                    {
                        CreateChests(1);
                    });
                }
            }
        }
Ejemplo n.º 19
0
        void NewGame()
        {
            var assets = Resolve <IAssetManager>();

            PartyMembers.Clear();
            foreach (PartyCharacterId charId in Enum.GetValues(typeof(PartyCharacterId)))
            {
                PartyMembers.Add(charId, assets.LoadCharacter(AssetType.PartyMember, charId));
            }

            Npcs.Clear();
            foreach (NpcCharacterId charId in Enum.GetValues(typeof(NpcCharacterId)))
            {
                Npcs.Add(charId, assets.LoadCharacter(AssetType.Npc, charId));
            }

            Chests.Clear();
            foreach (ChestId id in Enum.GetValues(typeof(ChestId)))
            {
                Chests.Add(id, assets.LoadChest(id));
            }

            Merchants.Clear();
            foreach (MerchantId id in Enum.GetValues(typeof(MerchantId)))
            {
                Merchants.Add(id, assets.LoadMerchant(id));
            }

            _party.Clear();

            Raise(new AddPartyMemberEvent(PartyCharacterId.Tom));
            Raise(new AddPartyMemberEvent(PartyCharacterId.Rainer));
            Raise(new AddPartyMemberEvent(PartyCharacterId.Drirr));
            Raise(new AddPartyMemberEvent(PartyCharacterId.Sira));
            Raise(new AddPartyMemberEvent(PartyCharacterId.Mellthas));
            Raise(new AddPartyMemberEvent(PartyCharacterId.Khunag));

            SetupTestState();
            Raise(new ReloadAssetsEvent()); // No need to keep character info cached once we've loaded it. New game is also a good point to clear out state.
            Raise(new PartyChangedEvent());
            Raise(new LoadMapEvent(MapDataId.Toronto2DGesamtkarteSpielbeginn));
            Raise(new StartClockEvent());
            Loaded = true;
        }
Ejemplo n.º 20
0
        public override string ToString()
        {
            var sb = new StringBuilder();

            if (Coins > 0u)
            {
                sb.Append($"$emotecoins {Coins.ToString()} ");
            }
            if (Tokens > 0u)
            {
                sb.Append($"$emotetokens {Tokens.ToString()} ");
            }
            if (Chests > 0u)
            {
                sb.Append($"$emotechest {Chests.ToString()} ");
            }
            if (Spheres > 0u)
            {
                sb.Append($"$emotesphere {Spheres.ToString()} ");
            }
            if (Capsules > 0u)
            {
                sb.Append($"$emotecapsule {Capsules.ToString()} ");
            }
            if (Tickets > 0u)
            {
                sb.Append($"$emoteticket {Tickets.ToString()} ");
            }
            if (BonusDoubleExp > 0u)
            {
                sb.Append($"$emote2exp {BonusDoubleExp.ToString()} ");
            }
            if (BonusBotRespect > 0u)
            {
                sb.Append($"$emoterespect {BonusBotRespect.ToString()} ");
            }
            if (BonusRewind > 0u)
            {
                sb.Append($"$emoterewind {BonusRewind.ToString()} ");
            }

            return(sb.ToString().TrimEnd());
        }
Ejemplo n.º 21
0
 public void M_clear()
 {
     if (Chests != null)
     {
         Chests.M_clear();
     }
     if (Players != null)
     {
         Players.M_clear();
     }
     if (Records != null)
     {
         Records.M_clear();
     }
     if (Award != null)
     {
         Award.M_clear();
     }
 }
Ejemplo n.º 22
0
 public Chest GetChestAtTile(int x, int y)
 {
     return(Chests.FirstOrDefault(c => (c.X == x || c.X == x - 1) && (c.Y == y || c.Y == y - 1)));
 }
Ejemplo n.º 23
0
        public void Save(string filename, bool resetTime = false)
        {
            lock (_fileLock)
            {
                if (resetTime)
                {
                    OnProgressChanged(this, new ProgressChangedEventArgs(0, "Resetting Time..."));
                    ResetTime();
                }

                if (filename == null)
                {
                    return;
                }

                string temp = filename + ".tmp";
                using (var fs = new FileStream(temp, FileMode.Create))
                {
                    using (var bw = new BinaryWriter(fs))
                    {
                        bw.Write(World.CompatibleVersion);
                        bw.Write(Title);
                        bw.Write(WorldId);
                        bw.Write((int)LeftWorld);
                        bw.Write((int)RightWorld);
                        bw.Write((int)TopWorld);
                        bw.Write((int)BottomWorld);
                        bw.Write(TilesHigh);
                        bw.Write(TilesWide);
                        bw.Write(SpawnX);
                        bw.Write(SpawnY);
                        bw.Write(GroundLevel);
                        bw.Write(RockLevel);
                        bw.Write(Time);
                        bw.Write(DayTime);
                        bw.Write(MoonPhase);
                        bw.Write(BloodMoon);
                        bw.Write(DungeonX);
                        bw.Write(DungeonY);
                        bw.Write(DownedBoss1);
                        bw.Write(DownedBoss2);
                        bw.Write(DownedBoss3);
                        bw.Write(SavedGoblin);
                        bw.Write(SavedWizard);
                        bw.Write(SavedMech);
                        bw.Write(DownedGoblins);
                        bw.Write(DownedClown);
                        bw.Write(DownedFrost);
                        bw.Write(ShadowOrbSmashed);
                        bw.Write(SpawnMeteor);
                        bw.Write((byte)ShadowOrbCount);
                        bw.Write(AltarCount);
                        bw.Write(HardMode);
                        bw.Write(InvasionDelay);
                        bw.Write(InvasionSize);
                        bw.Write(InvasionType);
                        bw.Write(InvasionX);


                        for (int x = 0; x < TilesWide; ++x)
                        {
                            OnProgressChanged(this, new ProgressChangedEventArgs(x.ProgressPercentage(TilesWide), "Saving Tiles..."));

                            int rle = 0;
                            for (int y = 0; y < TilesHigh; y = y + rle + 1)
                            {
                                var curTile = Tiles[x, y];
                                bw.Write(curTile.IsActive);
                                if (curTile.IsActive)
                                {
                                    bw.Write(curTile.Type);
                                    if (TileProperties[curTile.Type].IsFramed)
                                    {
                                        bw.Write(curTile.U);
                                        bw.Write(curTile.V);

                                        // TODO: Let Validate handle these
                                        //validate chest entry exists
                                        if (curTile.Type == 21)
                                        {
                                            if (GetChestAtTile(x, y) == null)
                                            {
                                                Chests.Add(new Chest(x, y));
                                            }
                                        }
                                        //validate sign entry exists
                                        else if (curTile.Type == 55 || curTile.Type == 85)
                                        {
                                            if (GetSignAtTile(x, y) == null)
                                            {
                                                Signs.Add(new Sign(x, y, string.Empty));
                                            }
                                        }
                                    }
                                }
                                if ((int)curTile.Wall > 0)
                                {
                                    bw.Write(true);
                                    bw.Write(curTile.Wall);
                                }
                                else
                                {
                                    bw.Write(false);
                                }

                                if ((int)curTile.Liquid > 0)
                                {
                                    bw.Write(true);
                                    bw.Write(curTile.Liquid);
                                    bw.Write(curTile.IsLava);
                                }
                                else
                                {
                                    bw.Write(false);
                                }

                                bw.Write(curTile.HasWire);

                                int rleTemp = 1;
                                while (y + rleTemp < TilesHigh && curTile.Equals(Tiles[x, (y + rleTemp)]))
                                {
                                    ++rleTemp;
                                }
                                rle = rleTemp - 1;
                                bw.Write((short)rle);
                            }
                        }
                        OnProgressChanged(null, new ProgressChangedEventArgs(100, "Saving Chests..."));
                        for (int i = 0; i < 1000; ++i)
                        {
                            if (i >= Chests.Count)
                            {
                                bw.Write(false);
                            }
                            else
                            {
                                Chest curChest = Chests[i];
                                bw.Write(true);
                                bw.Write(curChest.X);
                                bw.Write(curChest.Y);
                                for (int j = 0; j < Chest.MaxItems; ++j)
                                {
                                    if (curChest.Items.Count > j)
                                    {
                                        bw.Write((byte)curChest.Items[j].StackSize);
                                        if (curChest.Items[j].StackSize > 0)
                                        {
                                            bw.Write(curChest.Items[j].NetId); // TODO Verify
                                            bw.Write(curChest.Items[j].Prefix);
                                        }
                                    }
                                    else
                                    {
                                        bw.Write((byte)0);
                                    }
                                }
                            }
                        }
                        OnProgressChanged(null, new ProgressChangedEventArgs(100, "Saving Signs..."));
                        for (int i = 0; i < 1000; ++i)
                        {
                            if (i >= Signs.Count || string.IsNullOrWhiteSpace(Signs[i].Text))
                            {
                                bw.Write(false);
                            }
                            else
                            {
                                var curSign = Signs[i];
                                bw.Write(true);
                                bw.Write(curSign.Text);
                                bw.Write(curSign.X);
                                bw.Write(curSign.Y);
                            }
                        }
                        OnProgressChanged(null, new ProgressChangedEventArgs(100, "Saving NPC Data..."));
                        foreach (NPC curNpc in NPCs)
                        {
                            bw.Write(true);
                            bw.Write(curNpc.Name);
                            bw.Write(curNpc.Position.X);
                            bw.Write(curNpc.Position.Y);
                            bw.Write(curNpc.IsHomeless);
                            bw.Write(curNpc.Home.X);
                            bw.Write(curNpc.Home.Y);
                        }
                        bw.Write(false);

                        OnProgressChanged(null, new ProgressChangedEventArgs(100, "Saving NPC Names..."));
                        bw.Write(CharacterNames.FirstOrDefault(c => c.Id == 17).Name);
                        bw.Write(CharacterNames.FirstOrDefault(c => c.Id == 18).Name);
                        bw.Write(CharacterNames.FirstOrDefault(c => c.Id == 19).Name);
                        bw.Write(CharacterNames.FirstOrDefault(c => c.Id == 20).Name);
                        bw.Write(CharacterNames.FirstOrDefault(c => c.Id == 22).Name);
                        bw.Write(CharacterNames.FirstOrDefault(c => c.Id == 54).Name);
                        bw.Write(CharacterNames.FirstOrDefault(c => c.Id == 38).Name);
                        bw.Write(CharacterNames.FirstOrDefault(c => c.Id == 107).Name);
                        bw.Write(CharacterNames.FirstOrDefault(c => c.Id == 108).Name);
                        bw.Write(CharacterNames.FirstOrDefault(c => c.Id == 124).Name);

                        OnProgressChanged(null, new ProgressChangedEventArgs(100, "Saving Validation Data..."));
                        bw.Write(true);
                        bw.Write(Title);
                        bw.Write(WorldId);
                        bw.Close();
                        fs.Close();

                        // make a backup of current file if it exists
                        if (File.Exists(filename))
                        {
                            string backup = filename + ".TEdit";
                            File.Copy(filename, backup, true);
                        }
                        // replace actual file with temp save file
                        File.Copy(temp, filename, true);
                        // delete temp save file
                        File.Delete(temp);
                        OnProgressChanged(null, new ProgressChangedEventArgs(0, "World Save Complete."));
                    }
                }

                _lastSave = File.GetLastWriteTimeUtc(filename);
            }
        }
Ejemplo n.º 24
0
        public ReadManager(Variables var, Game1 g, Enums enums) // Placement of created instances of object.
        {
            this.enums   = enums;
            enums.pClass = PlayerClass.Mage;
            im           = new InventoryManager(this);
            List <string> strings = new List <string>();
            StreamReader  sr      = new StreamReader("map.txt");

            while (!sr.EndOfStream)
            {
                strings.Add(sr.ReadLine());
            }
            sr.Close();

            tiles = new Tile[strings[0].Length, strings.Count];
            for (int i = 0; i < tiles.GetLength(0); i++)
            {
                for (int j = 0; j < tiles.GetLength(1); j++)
                {
                    if (strings[j][i] == 'f')
                    {
                        tiles[i, j] = new Tile(var.floor, new Vector2(32 * i, 32 * j), true, var.floorRec);
                        tileList.Add(tiles[i, j]);
                        gameObjects.Add(tiles[i, j]);
                    }
                    else if (strings[j][i] == '-')
                    {
                    }
                    else if (strings[j][i] == 'h')
                    {
                        if (enums.pClass == PlayerClass.Warrior)
                        {
                            warrior = new Warrior(var.hero, new Vector2(32 * i, 32 * j), false, var.heroRec, this, g.Content, var.fakeTextureHero);
                            heroes.Add(warrior);
                        }
                        else if (enums.pClass == PlayerClass.Mage)
                        {
                            mage = new Mage(var.hero, new Vector2(32 * i, 32 * j), false, var.heroRec, this, g.Content, var.fakeTextureHero);
                            heroes.Add(mage);
                        }
                    }
                    else if (strings[j][i] == 'g')
                    {
                        green = new Goblin(var.greenMonster, new Vector2(32 * i, 32 * j), false, var.greenMonsterRec, this);
                        monsters.Add(green);
                    }
                    else if (strings[j][i] == 'd')
                    {
                        devil = new Devil(var.greenMonster, new Vector2(32 * i, 32 * j), false, var.greenMonsterRec, this);
                        monsters.Add(devil);
                    }
                    else if (strings[j][i] == 'c')
                    {
                        chest = new Chests(var.chestClosed, new Vector2(32 * i, 32 * j), false, var.chestRec, im, false, false, var.chestOpen, g);
                        chestList.Add(chest);
                    }
                    else if (strings[j][i] == 'i')
                    {
                        tiles[i, j] = new Tile(var.floor, new Vector2(32 * i, 32 * j), false, var.floorRec);
                        invisibleTiles.Add(tiles[i, j]);
                    }
                    else if (strings[j][i] == 's')
                    {
                        dSpikeTrap = new DynamicSpikeTrap(var.spikeTrapSS, new Vector2(32 * i, (32 * j) + 15), false, var.spikeRec, var.fakeTextureSpike, this);
                        spikeList.Add(dSpikeTrap);
                        dGameObjects.Add(dSpikeTrap);
                    }
                    else if (strings[j][i] == 'r')
                    {
                        rBlock = new RestorationBlock(var.restoFloor, new Vector2(32 * i, 32 * j), true, var.floorRec, this);
                        restoList.Add(rBlock);
                        gameObjects.Add(rBlock);
                    }
                    else if (strings[j][i] == 'l')
                    {
                        lever = new Lever(var.leverTex, new Vector2(32 * i, (32 * j) + 15), false, var.leverRec);
                        leverList.Add(lever);
                        gameObjects.Add(lever);
                    }
                }
            }
        }
Ejemplo n.º 25
0
 // since we are using these functions to add chests into the world we don't need to check all spots, only the anchor spot
 public Chest GetChestAtTile(int x, int y, bool findOrigin = false)
 {
     return(Chests.FirstOrDefault(c => (c.X == x) && (c.Y == y)));
 }
Ejemplo n.º 26
0
        public void Validate()
        {
            for (int x = 0; x < TilesWide; x++)
            {
                OnProgressChanged(this,
                                  new ProgressChangedEventArgs((int)(x / (float)TilesWide * 100.0), "Validating World..."));

                for (int y = 0; y < TilesHigh; y++)
                {
                    Tile curTile = Tiles[x, y];

                    if (curTile.Type == (int)TileType.IceByRod)
                    {
                        curTile.IsActive = false;
                    }

                    // TODO: Let Validate handle these
                    //validate chest entry exists
                    if (Tile.IsChest(curTile.Type))
                    {
                        if (GetChestAtTile(x, y) == null)
                        {
                            Chests.Add(new Chest(x, y));
                        }
                    }
                    //validate sign entry exists
                    else if (Tile.IsSign(curTile.Type))
                    {
                        if (GetSignAtTile(x, y) == null)
                        {
                            Signs.Add(new Sign(x, y, string.Empty));
                        }
                    }
                }
            }

            foreach (Chest chest in Chests.ToArray())
            {
                bool removed = false;
                for (int x = chest.X; x < chest.X + 1; x++)
                {
                    for (int y = chest.Y; y < chest.Y + 1; y++)
                    {
                        if (!Tiles[x, y].IsActive || !Tile.IsChest(Tiles[x, y].Type))
                        {
                            Chests.Remove(chest);
                            removed = true;
                            break;
                        }
                    }
                    if (removed)
                    {
                        break;
                    }
                }
            }

            foreach (Sign sign in Signs.ToArray())
            {
                if (sign.Text == null)
                {
                    Signs.Remove(sign);
                    continue;
                }

                bool removed = false;
                for (int x = sign.X; x < sign.X + 1; x++)
                {
                    for (int y = sign.Y; y < sign.Y + 1; y++)
                    {
                        if (!Tiles[x, y].IsActive || !Tile.IsSign(Tiles[x, y].Type))
                        {
                            Signs.Remove(sign);
                            removed = true;
                            break;
                        }
                    }
                    if (removed)
                    {
                        break;
                    }
                }
            }
            OnProgressChanged(this,
                              new ProgressChangedEventArgs(0, "Validating Complete..."));
            if (Chests.Count > 1000)
            {
                throw new ArgumentOutOfRangeException(string.Format("Chest Count is {0} which is greater than 1000", Chests.Count));
            }
            if (Signs.Count > 1000)
            {
                throw new ArgumentOutOfRangeException(string.Format("Sign Count is {0} which is greater than 1000", Signs.Count));
            }
        }
Ejemplo n.º 27
0
    /// <summary>
    /// Lo utilizamos para procesar el JSON que nos llega desde el servidor.
    /// </summary>
    /// <param name="json">JSON que nos envía el servidor.</param>
    IEnumerator ProcessJSON(JSONNode json)
    {
        if (json["type"].Value == INITIAL_REQUEST)
        {
            MapWidth   = json["width"].AsInt;
            MapHeight  = json["height"].AsInt;
            MapVersion = json["map_version"].AsInt;
            var playerSpawnPosition = json["spawn"].ReadVector3();
            _playerId = json["playerId"].AsInt;

            var obstacleParent = new GameObject("Obstacles").transform;

            var mapNode   = json["map"];
            var obstacles = new int[mapNode.AsArray.Count, mapNode.AsArray[0].AsArray.Count];

            for (int i = 0; i < mapNode.AsArray.Count; i++)
            {
                for (int j = 0; j < mapNode.AsArray[i].AsArray.Count; j++)
                {
                    obstacles[i, j] = mapNode.AsArray[i].AsArray[j].AsInt;
                }
            }

            BuildMap(obstacles);
            var go = Instantiate(PlayerPrefab, playerSpawnPosition, Quaternion.identity);
            _player      = go.GetComponent <Player>();
            _player.Name = PlayerPrefs.GetString("playerName");
            _characters.Add(_player);
            GenerateBorders();
            StartCoroutine(NetworkUpdateLoop());
        }
        else if (json["type"].Value == UPDATE_REQUEST)
        {
            var gameState = json["state"];
            RemainingTime = gameState["timer"].AsInt;
            // Lista de cambios que tenemos que hacer en el mapa
            foreach (var version in gameState["map_changes"].AsArray)
            {
                MapVersion++;
                foreach (var change in version.Value.AsArray)
                {
                    var k = change.Value.AsInt;
                    if (Obstacles.ContainsKey(k))
                    {
                        iTween.ScaleTo(Obstacles[k], iTween.Hash("scale", Vector3.zero, "time", .5f));
                        Destroy(Obstacles[k], 0.5f);
                        Obstacles.Remove(k);
                    }
                }
            }

            foreach (var bomb in gameState["bombs"].AsArray)
            {
                var timer  = bomb.Value["timer"].AsFloat;
                var bombId = bomb.Value["id"].AsInt;

                if (!Bombs.ContainsKey(bombId))
                {
                    Bombs[bombId] = Instantiate(BombPrefab, bomb.Value.ReadVector3(), Quaternion.identity);
                    Bombs[bombId].GetComponent <Bomb>().TimeToExplode = timer;
                    Bombs[bombId].GetComponent <Bomb>().Id            = bombId;
                    SetSortingOrder(Bombs[bombId]);
                }
            }

            foreach (var chest in gameState["chests"].AsArray)
            {
                var chestId = chest.Value["id"].AsInt;

                if (!Chests.ContainsKey(chestId))
                {
                    Chests[chestId] = Instantiate(ChestPrefab, chest.Value.ReadVector3(), Quaternion.identity);
                    Chests[chestId].GetComponent <SpawnedObject>().Id = chestId;
                    SetSortingOrder(Chests[chestId].gameObject);
                }
            }

            // Hacemos una copia de los players que tenemos controlados
            otherPlayersControl = new Dictionary <int, OtherPlayer>(_otherPlayers);

            foreach (var pair in gameState["players"])
            {
                var key   = int.Parse(pair.Key);
                var value = pair.Value;
                // Si estamos actualizando los otros personajes
                if (key != _playerId)
                {
                    if (!_otherPlayers.ContainsKey(key))
                    {
                        // Jugador que no tenemos instanciado. lo instanciamos
                        var otherPlayer = Instantiate(OtherPlayerPrefab).GetComponent <OtherPlayer>();
                        otherPlayer.Name   = value["playerName"];
                        _otherPlayers[key] = otherPlayer;
                    }

                    // Elimino personaje si existe en la partida actual y me quedo con los que ya no esten
                    // para mantener un control de que ha cambiado
                    if (otherPlayersControl.ContainsKey(key))
                    {
                        otherPlayersControl.Remove(key);
                    }
                    // Actualizamos su posicion, velocidad y puntuacion
                    _otherPlayers[key].GetComponent <Character>().SetPosition(new Vector2(pair.Value["position"]["x"], pair.Value["position"]["y"]));
                    _otherPlayers[key].GetComponent <OtherPlayer>().Velocity = pair.Value["velocity"];
                    _otherPlayers[key].GetComponent <OtherPlayer>().Score    = pair.Value["score"];

                    // Si el servidor dice que siguen vivos, actualizar su vida
                    if (_otherPlayers[key].GetComponent <Health>().CurrentHealth > 0)
                    {
                        _otherPlayers[key].GetComponent <Health>().CurrentHealth = pair.Value["health"];
                    }
                    else  // Si dice que estan muertos, destruirlos
                    {
                        _otherPlayers[key].GetComponent <Health>().CurrentHealth = 0;
                    }
                }
                // Si estamos actualizando nuestro personaje
                else
                {
                    // Actualizamos su vida y puntuacion
                    _player.GetComponent <Health>().CurrentHealth = pair.Value["health"];
                    _player.GetComponent <Character>().Score      = pair.Value["score"];
                }

                // Actualizamos la puntuacion, de forma que siempre mantenga la
                // Mas alta
                if (pair.Value["score"].AsInt >= highscore)
                {
                    highscore          = pair.Value["score"].AsInt;
                    highscoreText.text = "Top: " + pair.Value["playerName"] + " " + pair.Value["score"];
                }
            }

            // Los que quedan en el control son los que se han desconectado
            // Han muerto o han sufrido algun problema en red
            // Los eliminamos de otherPlayers
            if (otherPlayersControl.Count > 0)
            {
                foreach (var pair in otherPlayersControl)
                {
                    _otherPlayers[pair.Key].GetComponent <Health>().CurrentHealth = 0;
                    Destroy(_otherPlayers[pair.Key].gameObject);
                    _otherPlayers.Remove(pair.Key);
                }
                // Si hemos usado el diccionario de control, lo reestablecemos
                otherPlayersControl.Clear();
            }
        }
        yield return(null);
    }
Ejemplo n.º 28
0
        public Chest GetChestAtTile(int x, int y)
        {
            Vector2Int32 anchor = GetAnchor(x, y);

            return(Chests.FirstOrDefault(c => (c.X == anchor.X) && (c.Y == anchor.Y)));
        }
Ejemplo n.º 29
0
        public Chest GetChestAtTile(int x, int y, bool findOrigin = false)
        {
            Vector2Int32 anchor = findOrigin ? GetAnchor(x, y) : new Vector2Int32(x, y);

            return(Chests.FirstOrDefault(c => (c.X == anchor.X) && (c.Y == anchor.Y)));
        }
Ejemplo n.º 30
0
        public void Validate()
        {
            var t = TaskFactoryHelper.UiTaskFactory.StartNew(() =>
            {
                for (int x = 0; x < TilesWide; x++)
                {
                    OnProgressChanged(this,
                                      new ProgressChangedEventArgs((int)(x / (float)TilesWide * 100.0), "Validating World..."));

                    for (int y = 0; y < TilesHigh; y++)
                    {
                        Tile curTile = Tiles[x, y];

                        if (curTile.Type == (int)TileType.IceByRod)
                        {
                            curTile.IsActive = false;
                        }

                        ValSpecial(x, y);
                    }
                }
            });

            foreach (Chest chest in Chests.ToArray())
            {
                bool removed = false;
                for (int x = chest.X; x < chest.X + 1; x++)
                {
                    for (int y = chest.Y; y < chest.Y + 1; y++)
                    {
                        if (!Tiles[x, y].IsActive || !Tile.IsChest(Tiles[x, y].Type))
                        {
                            Chests.Remove(chest);
                            removed = true;
                            break;
                        }
                    }
                    if (removed)
                    {
                        break;
                    }
                }
            }

            foreach (Sign sign in Signs.ToArray())
            {
                if (sign.Text == null)
                {
                    Signs.Remove(sign);
                    continue;
                }

                bool removed = false;
                for (int x = sign.X; x < sign.X + 1; x++)
                {
                    for (int y = sign.Y; y < sign.Y + 1; y++)
                    {
                        if (!Tiles[x, y].IsActive || !Tile.IsSign(Tiles[x, y].Type))
                        {
                            Signs.Remove(sign);
                            removed = true;
                            break;
                        }
                    }
                    if (removed)
                    {
                        break;
                    }
                }
            }


            foreach (TileEntity tileEntity in TileEntities.ToArray())
            {
                int x      = tileEntity.PosX;
                int y      = tileEntity.PosY;
                var anchor = GetAnchor(x, y);
                if (!Tiles[anchor.X, anchor.Y].IsActive || !Tile.IsTileEntity(Tiles[anchor.X, anchor.Y].Type))
                {
                    TaskFactoryHelper.ExecuteUiTask(() => TileEntities.Remove(tileEntity));
                }
            }

            OnProgressChanged(this,
                              new ProgressChangedEventArgs(0, "Validating Complete..."));

            if (Chests.Count > World.MaxChests)
            {
                throw new ArgumentOutOfRangeException($"Chest Count is {Chests.Count} which is greater than {World.MaxChests}.");
            }
            if (Signs.Count > World.MaxSigns)
            {
                throw new ArgumentOutOfRangeException($"Sign Count is {Signs.Count} which is greater than {World.MaxSigns}.");
            }
        }