Inheritance: MonoBehaviour, ISaveable
Example #1
0
 public MiniMap(DungeonInformation info, TileEntity[] tiles)
 {
     Info = info;
     Tiles = tiles;
     var size = info.CurrentFloor.FloorRect.size;
     TileDetectionTable = new bool[(int)size.x,(int)size.y];
 }
Example #2
0
 public static TileEntityIChest getChestType(TileEntity te)
 {
     switch (te.ID)
     {
         case "IRON":
             TileEntityIronChest _itec = te as TileEntityIronChest;
             return _itec;
         case "GOLD":
             TileEntityGoldChest _gtec = te as TileEntityGoldChest;
             return _gtec;
         case "DIAMOND":
             TileEntityDiamondChest _dtec = te as TileEntityDiamondChest;
             return _dtec;
         case "COPPER":
             TileEntityCopperChest _cptec = te as TileEntityCopperChest;
             return _cptec;
         case "SILVER":
             TileEntitySilverChest _stec = te as TileEntitySilverChest;
             return _stec;
         case "CRYSTAL":
             TileEntityCrystalChest _ctec = te as TileEntityCrystalChest;
             return _ctec;
         default:
             TileEntityIronChest tec = te as TileEntityIronChest;
             return tec;
     }
 }
        public void SetTileEntity (int x, int y, int z, TileEntity te)
        {
            BlockInfoEx info = BlockInfo.BlockTable[_blocks[x, y, z]] as BlockInfoEx;
            if (info == null) {
                throw new InvalidOperationException("The given block is of a type that does not support TileEntities.");
            }

            if (te.GetType() != TileEntityFactory.Lookup(info.TileEntityName)) {
                throw new ArgumentException("The TileEntity type is not valid for this block.", "te");
            }

            BlockKey key = (TranslateCoordinates != null)
                ? TranslateCoordinates(x, y, z)
                : new BlockKey(x, y, z);

            TagNodeCompound oldte;

            if (_tileEntityTable.TryGetValue(key, out oldte)) {
                _tileEntities.Remove(oldte);
            }

            te.X = key.x;
            te.Y = key.y;
            te.Z = key.z;

            TagNodeCompound tree = te.BuildTree() as TagNodeCompound;

            _tileEntities.Add(tree);
            _tileEntityTable[key] = tree;
        }
Example #4
0
 public static TileEntityIChest getChestType(TileEntity te, int blockdata)
 {
     switch (blockdata)
     {
         case 0:
             TileEntityIronChest _itec = te as TileEntityIronChest;
             return _itec;
         case 1:
             TileEntityGoldChest _gtec = te as TileEntityGoldChest;
             return _gtec;
         case 2:
             TileEntityDiamondChest _dtec = te as TileEntityDiamondChest;
             return _dtec;
         case 3:
             TileEntityCopperChest _cptec = te as TileEntityCopperChest;
             return _cptec;
         case 4:
             TileEntitySilverChest _stec = te as TileEntitySilverChest;
             return _stec;
         case 5:
             TileEntityCrystalChest _ctec = te as TileEntityCrystalChest;
             return _ctec;
         default:
             TileEntityIronChest tec = te as TileEntityIronChest;
             return tec;
     }
 }
Example #5
0
 public TileEntityControl(TileEntity te)
     : base(te)
 {
     TileEntityControl tes = te as TileEntityControl;
     if (tes != null) {
         _command = tes._command;
     }
 }
Example #6
0
 public MiniMap()
 {
     Info = GameController.DungeonInformation;
     TileDetectionTable = new bool[256, 256];
     Tiles = new TileEntity[] { };
     //GateWays = new GateWayEntity[] { };
     createMapTexure(Vector2.one*256);
 }
 public TileEntityMusic (TileEntity te)
     : base(te)
 {
     TileEntityMusic tes = te as TileEntityMusic;
     if (tes != null) {
         _note = tes._note;
     }
 }
 public TileEntityRecordPlayer(TileEntity te)
     : base(te)
 {
     TileEntityRecordPlayer tes = te as TileEntityRecordPlayer;
     if (tes != null) {
         _record = tes._record;
     }
 }
 public TileEntityMobSpawner(TileEntity te)
     : base(te)
 {
     TileEntityMobSpawner tes = te as TileEntityMobSpawner;
     if (tes != null) {
         _delay = tes._delay;
         _entityID = tes._entityID;
     }
 }
Example #10
0
 public TileEntityBeacon(TileEntity te)
     : base(te)
 {
     TileEntityBeacon tes = te as TileEntityBeacon;
     if (tes != null) {
         _levels = tes._levels;
         _primary = tes._primary;
         _secondary = tes._secondary;
     }
 }
Example #11
0
 public TileEntityChest(TileEntity te)
     : base(te)
 {
     TileEntityChest tec = te as TileEntityChest;
     if (tec != null) {
         _items = tec._items.Copy();
     }
     else {
         _items = new ItemCollection(_CAPACITY);
     }
 }
Example #12
0
 public TileEntitySign(TileEntity te)
     : base(te)
 {
     TileEntitySign tes = te as TileEntitySign;
     if (tes != null) {
         _text1 = tes._text1;
         _text2 = tes._text2;
         _text3 = tes._text3;
         _text4 = tes._text4;
     }
 }
 public TileEntityPiston(TileEntity te)
     : base(te)
 {
     TileEntityPiston tes = te as TileEntityPiston;
     if (tes != null) {
         _blockId = tes._blockId;
         _blockData = tes._blockData;
         _facing = tes._facing;
         _progress = tes._progress;
         _extending = tes._extending;
     }
 }
 public TileEntityBrewingStand(TileEntity te)
     : base(te)
 {
     TileEntityBrewingStand tec = te as TileEntityBrewingStand;
     if (tec != null) {
         _items = tec._items.Copy();
         _brewTime = tec._brewTime;
     }
     else {
         _items = new ItemCollection(_CAPACITY);
     }
 }
 public TileEntityFurnace (TileEntity te)
     : base(te)
 {
     TileEntityFurnace tec = te as TileEntityFurnace;
     if (tec != null) {
         _cookTime = tec._cookTime;
         _burnTime = tec._burnTime;
         _items = tec._items.Copy();
     }
     else {
         _items = new ItemCollection(_CAPACITY);
     }
 }
        public TileEntityMobSpawner(TileEntity te)
            : base(te)
        {
            TileEntityMobSpawner tes = te as TileEntityMobSpawner;
            if (tes != null) {
                _delay = tes._delay;
                _entityID = tes._entityID;
                _maxDelay = tes._maxDelay;
                _minDelay = tes._minDelay;
                _spawnCount = tes._spawnCount;
                _spawnRange = tes._spawnRange;
                _maxNearbyEnemies = tes._maxNearbyEnemies;
                _requiredPlayerRange = tes._requiredPlayerRange;
                _maxExperience = tes._maxExperience;
                _remainingExperience = tes._remainingExperience;
                _experienceRegenTick = tes._experienceRegenTick;
                _experienceRegenRate = tes._experienceRegenRate;
                _experienceRegenAmount = tes._experienceRegenAmount;

                if (tes._spawnData != null)
                    _spawnData = tes._spawnData.Copy() as TagNodeCompound;
            }
        }
Example #17
0
 public AStarUserContext(IsoMap map, TileEntity entity, Dictionary <TileEntity, bool> whiteList = null)
 {
     this.map       = map;
     this.entity    = entity;
     this.whiteList = whiteList;
 }
 public TileEntityEndPortal (TileEntity te)
     : base(te)
 {
 }
 private static void init(DungeonParameter dgparam)
 {
     if (Init) return;
     GameObject obj = GameObject.Instantiate(org);
     obj.SetActive(false);
     TileEntity ret = obj.GetComponent<TileEntity>();
     ret.init(new Wall(),dgparam);
     WallObj = ret;
     //
     obj = GameObject.Instantiate(org);
     obj.SetActive(false);
     ret = obj.GetComponent<TileEntity>();
     ret.init(new Road(),dgparam);
     RoadObj = ret;
     //
     obj = GameObject.Instantiate(org);
     obj.SetActive(false);
     ret = obj.GetComponent<TileEntity>();
     ret.init(new WaterWay(),dgparam);
     WaterwayObj = ret;
     Init = true;
 }
    public bool canExertion(PlayerController player)
    {
        if (MyCharacterController.getDirectionDelta(player.CurrentDirection).magnitude != 1) return false;
        var find = Physics2D.OverlapPoint(player.FrontPos, TagList.getLayerMask(TagList.Wall));
        if (find != null) {
            Tile = find.GetComponent<TileEntity>();
            return true;
        }

        return false;
    }
 public TileEntityEndPortal(TileEntity te)
     : base(te)
 {
 }
Example #22
0
        /// <inheritdoc/>
        public void SetTileEntity(int x, int y, int z, TileEntity te)
        {
            cache = GetChunk(x, y, z);
            if (cache == null || !Check(x, y, z)) {
                return;
            }

            cache.Blocks.SetTileEntity(x & chunkXMask, y & chunkYMask, z & chunkZMask, te);
        }
Example #23
0
 public int AddDelayAi <TResult>(TileEntity entity, Action <DelayAiObject <TResult> > callback, IEnumerable <TResult> iterator)
 {
     return(AddDelayAi <TResult>(entity, callback, iterator.GetEnumerator()));
 }
Example #24
0
    public static TileEntity Create(OwnerType owner, EntityModel model, bool isFriendly = false)
    {
        var entityObj  = LoadAndCreate(model);
        var tileEntity = new TileEntity();

        tileEntity.owner      = owner;
        tileEntity.model      = model;
        tileEntity.State      = EntityStateType.Idle;
        tileEntity.aiType     = (EntityAiType)model.targetType;
        tileEntity.entityType = model.entityType;
        tileEntity.Friendly   = isFriendly;
        if (model.tileSize > 0)
        {
            tileEntity.width = tileEntity.height = model.tileSize * 2;      //  REMARK:建筑实际占用格子扩大2倍
        }
        else
        {
            tileEntity.width = tileEntity.height = 1;
        }
        tileEntity.currentHp           = tileEntity.maxHp = Mathf.Max(model.hp, 1); //  REMARK:这里设置最大hp的最小值为1,不然对于工人等直接就是dead状态。
        tileEntity.animationNamePrefix = model.nameForResource + "_";

        //  REMARK:建筑按照格子建造、士兵按照边行走(所以士兵位置比建筑偏移(0.5,0.5))
        if (EntityTypeUtil.IsAnyActor(model.entityType))
        {
            tileEntity.renderTileSizeOffset = new Vector2((tileEntity.width * 0.5f) - 1.0f, (tileEntity.height * 0.5f) - 1.0f);
        }
        else
        {
            tileEntity.renderTileSizeOffset = new Vector2((tileEntity.width * 0.5f) - 0.5f, (tileEntity.height * 0.5f) - 0.5f);
        }
        tileEntity.view = entityObj.GetComponent <EntityViewComponent>();
        if (tileEntity.view == null)
        {
            if (EntityTypeUtil.IsAnyActor(tileEntity.entityType))
            {
                tileEntity.view = entityObj.AddComponent <ActorView>();
            }
            else if (EntityTypeUtil.IsAnyTower(tileEntity.entityType))
            {
                tileEntity.view = entityObj.AddComponent <TowerView>();
            }
            else
            {
                tileEntity.view = entityObj.AddComponent <EntityViewComponent>();
            }
        }

        if (EntityTypeUtil.IsAnyBuilding(tileEntity.entityType))//[建筑类]
        {
            //1格以上建筑有地皮
            if (model.tileSize > 2)
            {
                var floorBase = (GameObject)ResourceManager.Instance.LoadAndCreate(model.raceType + "/Entities/Misc/Floor4");//地皮
                tileEntity.view.AddSubView(floorBase, Vector3.zero);
                IsoHelper.FaceToWorldCamera(floorBase.transform);
                IsoHelper.MoveAlongCamera(floorBase.transform, Constants.FLOOR_Z_ORDER);
                floorBase.transform.localScale = Vector3.one * model.tileSize / 4;//REMARK 现有素材占4x4个tilesize
            }

            if (EntityTypeUtil.IsBarracks(model))
            {
                tileEntity.blockingRange = 3;
            }
            else
            {
                tileEntity.blockingRange = model.tileSize * 2 - 1;
            }
            tileEntity.AddComponent <ConstructBuildingComponent>();
            if (model.entityType == EntityType.Tower)
            {
                tileEntity.AddComponent <TowerComponent>();
            }
            else if (model.entityType == EntityType.Wall)
            {
                tileEntity.AddComponent <WallComponent>();
            }
            else if (EntityTypeUtil.IsGatherResourceBuilding(model))
            {
                tileEntity.AddComponent <GatherResourceBuildingComponent>();
            }
            else if (EntityTypeUtil.IsStorageResoruceBuilding(model))
            {
                tileEntity.AddComponent <ResourceStorageBuildingComponent>();
            }
            else if (EntityTypeUtil.IsArmyShop(model))
            {
                tileEntity.AddComponent <ProductSoldierBuildingComponent>();
            }
            else if (EntityTypeUtil.IsSkillShop(model))
            {
                tileEntity.AddComponent <ProductSkillBuildingComponent>();
            }
            else if (EntityTypeUtil.IsWorkerHouse(model))
            {
                tileEntity.AddComponent <WorkerHouseComponent>();
            }
            else if (EntityTypeUtil.IsFederal(model))
            {
                tileEntity.AddComponent <FederalComponent>();
            }
            else if (EntityTypeUtil.IsResearch(model))
            {
                tileEntity.AddComponent <ResearchBuildingComponent>();
            }
        }
        else if (EntityTypeUtil.IsAnyActor(model.entityType))   //[角色类]
        {
            //  战斗模式 家园模式 通用组件
            tileEntity.AddComponent <ActorMoveComponent>();
            if (GameWorld.Instance.worldType == WorldType.Home || GameWorld.Instance.worldType == WorldType.Visit) //家园模式 或者 访问模式
            {
                //  家园模式
                //  工人(添加工人组件&添加到工人小屋中)
                if (EntityTypeUtil.IsWorker(model))
                {
                    tileEntity.AddComponent <WorkmanComponent>();
                    var houseComp = IsoMap.Instance.GetWorkerHouseComponent();
                    Assert.Should(houseComp != null, "worker house is not exist...");
                    houseComp.AddAWorkman(tileEntity);
                }
                else
                {
                    tileEntity.AddComponent <ArmyComponent>();
                }
            }
            else                                                                                                    //战斗模式
            {
                tileEntity.AddComponent <GameBufferComponent>();
                //  设置士兵的监视范围(寻找目标用)    REMARK:设定为4.0秒可以移动的范围
                tileEntity.monitorRange = Mathf.Clamp(model.speed * 4.0f, 5.0f, 20.0f);
                if (EntityTypeUtil.IsBombMan(model))
                {
                    tileEntity.monitorRange = 0.0f;     //  暂时不限制炸弹人
                    tileEntity.AddComponent <BombManComponent>();
                }
                else if (EntityTypeUtil.IsCurer(model))
                {
                    tileEntity.AddComponent <CurerComponent>();
                }
                else if (isFriendly)                    //  友军/援军
                {
                    tileEntity.AddComponent <FriendComponent>();
                }
                else
                {
                    tileEntity.AddComponent <ActorComponent>();
                }
                //  除【友军/援军】以外添加拆墙组件(REMARK:友军/援军不可拆墙)
                if (!isFriendly)
                {
                    tileEntity.AddComponent <ActorDestroyWallComponent>();
                }
            }
        }
        else if (EntityTypeUtil.IsAnyTrap(model))   //  [陷阱类]
        {
            tileEntity.AddComponent <TrapComponent>();
        }
        Assert.Should((tileEntity.blockingRange == 0 || (tileEntity.blockingRange % 2) == 1), "invalid blockingRange...");
        Assert.Should(tileEntity.blockingRange <= tileEntity.width - 1 && tileEntity.blockingRange <= tileEntity.height - 1, "invalid blockingRange...");
        return(tileEntity);
    }
    public void ReplaceEventUseCardOnTile(UnitEntity newUserEntity, CardEntity newCardEntity, TileEntity newTargetEntity)
    {
        var index     = GameEventComponentsLookup.EventUseCardOnTile;
        var component = CreateComponent <EventUseCardOnTile>(index);

        component.UserEntity   = newUserEntity;
        component.CardEntity   = newCardEntity;
        component.TargetEntity = newTargetEntity;
        ReplaceComponent(index, component);
    }
Example #26
0
        public void SaveStructure(Rectangle target)
        {
            TagCompound tag = new TagCompound();

            tag.Add("Width", Width);
            tag.Add("Height", Height);

            List <TileSaveData> data = new List <TileSaveData>();

            for (int x = target.X; x <= target.X + target.Width; x++)
            {
                for (int y = target.Y; y <= target.Y + target.Height; y++)
                {
                    Tile   tile = Framing.GetTileSafely(x, y);
                    string tileName;
                    string wallName;
                    string teName;
                    if (tile.type >= TileID.Count)
                    {
                        tileName = ModContent.GetModTile(tile.type).mod.Name + " " + ModContent.GetModTile(tile.type).Name;
                    }
                    else
                    {
                        tileName = tile.type.ToString();
                    }
                    if (tile.wall >= WallID.Count)
                    {
                        wallName = ModContent.GetModWall(tile.wall).mod.Name + " " + ModContent.GetModWall(tile.wall).Name;
                    }
                    else
                    {
                        wallName = tile.wall.ToString();
                    }

                    TileEntity  teTarget  = null; //grabbing TE data
                    TagCompound entityTag = null;

                    if (TileEntity.ByPosition.ContainsKey(new Point16(x, y)))
                    {
                        teTarget = TileEntity.ByPosition[new Point16(x, y)];
                    }

                    if (teTarget != null)
                    {
                        if (teTarget.type < 2)
                        {
                            teName = teTarget.type.ToString();
                        }
                        else
                        {
                            ModTileEntity entityTarget = ModTileEntity.GetTileEntity(teTarget.type);
                            if (entityTarget != null)
                            {
                                teName    = entityTarget.mod.Name + " " + entityTarget.Name;
                                entityTag = (teTarget as ModTileEntity).Save();
                            }
                            else
                            {
                                teName = "";
                            }
                        }
                    }
                    else
                    {
                        teName = "";
                    }

                    byte[] wireArray = new byte[]
                    {
                        (byte)tile.wire().ToInt(),
                        (byte)tile.wire2().ToInt(),
                        (byte)tile.wire3().ToInt(),
                        (byte)tile.wire4().ToInt()
                    };
                    data.Add(new TileSaveData(tile.active(), tileName, wallName, tile.frameX, tile.frameY, (short)tile.wallFrameX(), (short)tile.wallFrameY(),
                                              tile.slope(), tile.halfBrick(), tile.actuator(), !tile.nactive(), tile.liquid, tile.liquidType(), tile.color(), tile.wallColor(), wireArray,
                                              teName, entityTag));
                }
            }
            tag.Add("TileData", data);

            StructureCache.Add(tag);
            Main.NewText("Structure added. Total structure count: " + StructureCache.Count, Color.Cyan);

            TopLeft     = default;
            SecondPoint = false;
            Width       = 0;
            Height      = 0;
        }
Example #27
0
        private void ValidateAndRemoveChests()
        {
            if (Buffer == null || Buffer.LastTile == null)
            {
                return;
            }


            var lastTile         = Buffer.LastTile;
            var existingLastTile = _wvm.CurrentWorld.Tiles[lastTile.Location.X, lastTile.Location.Y];

            // remove deleted chests or signs if required
            if (Tile.IsChest(lastTile.Tile.Type))
            {
                if (!Tile.IsChest(existingLastTile.Type) || !existingLastTile.IsActive)
                {
                    var curchest = _wvm.CurrentWorld.GetChestAtTile(lastTile.Location.X, lastTile.Location.Y);
                    if (curchest != null)
                    {
                        _wvm.CurrentWorld.Chests.Remove(curchest);
                    }
                }
            }
            else if (Tile.IsSign(lastTile.Tile.Type))
            {
                if (!Tile.IsSign(existingLastTile.Type) || !existingLastTile.IsActive)
                {
                    var cursign = _wvm.CurrentWorld.GetSignAtTile(lastTile.Location.X, lastTile.Location.Y);
                    if (cursign != null)
                    {
                        _wvm.CurrentWorld.Signs.Remove(cursign);
                    }
                }
            }
            else if (Tile.IsTileEntity(lastTile.Tile.Type))
            {
                if (!Tile.IsTileEntity(existingLastTile.Type) || !existingLastTile.IsActive)
                {
                    var curTe = _wvm.CurrentWorld.GetTileEntityAtTile(lastTile.Location.X, lastTile.Location.Y);
                    if (curTe != null)
                    {
                        _wvm.CurrentWorld.TileEntities.Remove(curTe);
                    }
                }
            }

            // Add new chests and signs if required
            if (Tile.IsChest(existingLastTile.Type))
            {
                var curchest = _wvm.CurrentWorld.GetChestAtTile(lastTile.Location.X, lastTile.Location.Y);
                if (curchest == null)
                {
                    _wvm.CurrentWorld.Chests.Add(new Chest(lastTile.Location.X, lastTile.Location.Y));
                }
            }
            else if (Tile.IsSign(existingLastTile.Type))
            {
                var cursign = _wvm.CurrentWorld.GetSignAtTile(lastTile.Location.X, lastTile.Location.Y);
                if (cursign == null)
                {
                    _wvm.CurrentWorld.Signs.Add(new Sign(lastTile.Location.X, lastTile.Location.Y, string.Empty));
                }
            }
            else if (Tile.IsTileEntity(existingLastTile.Type))
            {
                var curTe = _wvm.CurrentWorld.GetTileEntityAtTile(lastTile.Location.X, lastTile.Location.Y);
                if (curTe == null)
                {
                    _wvm.CurrentWorld.TileEntities.Add(TileEntity.CreateForTile(existingLastTile, lastTile.Location.X, lastTile.Location.Y, _wvm.CurrentWorld.TileEntities.Count));
                }
            }
        }
Example #28
0
 public TileEntityEnchantmentTable(TileEntity te)
     : base(te)
 {
 }
Example #29
0
        /// <summary>
        /// Exports the <see cref="Schematic"/> object to a schematic file.
        /// </summary>
        /// <param name="path">The path to write out the schematic file to.</param>
        public void Export(string path)
        {
            int xdim = _blockset.XDim;
            int ydim = _blockset.YDim;
            int zdim = _blockset.ZDim;

            byte[] blockData = new byte[xdim * ydim * zdim];
            byte[] dataData  = new byte[xdim * ydim * zdim];

            YZXByteArray schemaBlocks = new YZXByteArray(_blockset.XDim, _blockset.YDim, _blockset.ZDim, blockData);
            YZXByteArray schemaData   = new YZXByteArray(_blockset.XDim, _blockset.YDim, _blockset.ZDim, dataData);

            TagNodeList entities     = new TagNodeList(TagType.TAG_COMPOUND);
            TagNodeList tileEntities = new TagNodeList(TagType.TAG_COMPOUND);

            for (int x = 0; x < xdim; x++)
            {
                for (int z = 0; z < zdim; z++)
                {
                    for (int y = 0; y < ydim; y++)
                    {
                        AlphaBlock block = _blockset.GetBlock(x, y, z);
                        schemaBlocks[x, y, z] = (byte)block.ID;
                        schemaData[x, y, z]   = (byte)block.Data;

                        TileEntity te = block.GetTileEntity();
                        if (te != null)
                        {
                            te.X = x;
                            te.Y = y;
                            te.Z = z;

                            tileEntities.Add(te.BuildTree());
                        }
                    }
                }
            }

            foreach (TypedEntity e in _entityset)
            {
                entities.Add(e.BuildTree());
            }

            TagNodeCompound schematic = new TagNodeCompound();

            schematic["Width"]  = new TagNodeShort((short)xdim);
            schematic["Length"] = new TagNodeShort((short)zdim);
            schematic["Height"] = new TagNodeShort((short)ydim);

            schematic["Entities"]     = entities;
            schematic["TileEntities"] = tileEntities;

            schematic["Materials"] = new TagNodeString("Alpha");

            schematic["Blocks"] = new TagNodeByteArray(blockData);
            schematic["Data"]   = new TagNodeByteArray(dataData);

            NBTFile schematicFile = new NBTFile(path);

            using (Stream nbtStream = schematicFile.GetDataOutputStream())
            {
                if (nbtStream == null)
                {
                    return;
                }

                NbtTree tree = new NbtTree(schematic, "Schematic");
                tree.WriteTo(nbtStream);
            }
        }
Example #30
0
        private void LoadWorld(string file, bool useXml = false)
        {
            GameManager.Game.Penumbra.Lights.Clear();
            GameManager.Game.Penumbra.Hulls.Clear();
            GameManager.Game.Player?.InitLighting();
            ((MainGameScreen)GameManager.Game.GameScreen)?.InitLighting();

            XmlDocument xmlDocument = new XmlDocument();

            if (useXml)
            {
                xmlDocument.LoadXml(file);
            }
            else
            {
                xmlDocument.Load(file);
            }

            foreach (XmlNode tile in xmlDocument["world"]["tiles"])
            {
                Tile fTile = ParseTile(tile);

                fTile.TileInfo.Tag = tile["tag"]?.InnerText;

                fTile.TileInfo.Tile = fTile;
                fTile.TileInfo.SetInteract(tile["textureKey"].InnerText);

                this.Tiles.Add(fTile);
            }
            foreach (XmlNode tile in xmlDocument["world"]["floorTiles"])
            {
                this.FloorTiles.Add(ParseTile(tile));
            }
            foreach (XmlNode tile in xmlDocument["world"]["decor"])
            {
                if (tile["textureKey"].InnerText == "torch")
                {
                    Torch torch = new Torch();
                    torch.X = int.Parse(tile["position"]["x"].InnerText) * 64;
                    torch.Y = int.Parse(tile["position"]["y"].InnerText) * 64;
                    Entity.Add(torch);
                    GameManager.Game.Penumbra.Lights.Add(new PointLight
                    {
                        Position     = new Vector2(torch.X + 32, torch.Y + 32),
                        Scale        = new Vector2(600),
                        ShadowType   = ShadowType.Illuminated,
                        CastsShadows = true,
                        Intensity    = 0.5f
                    });
                }
                else
                {
                    Tile fTile = ParseTile(tile);

                    this.Decor.Add(fTile);
                }
            }
            foreach (XmlNode tile in xmlDocument["world"]["entitys"])
            {
                if (GlobalAssets.EntityTextures[tile["textureKey"].InnerText].IsTile)
                {
                    TileEntity fTile = new TileEntity(new Frame(GlobalAssets.EntityTextures[tile["textureKey"].InnerText].Texture));
                    fTile.X             = int.Parse(tile["position"]["x"].InnerText) * 64;
                    fTile.Y             = int.Parse(tile["position"]["y"].InnerText) * 64;
                    fTile.Texture       = GlobalAssets.EntityTextures[tile["textureKey"].InnerText].Texture;
                    fTile.Size          = GlobalAssets.EntityTextures[tile["textureKey"].InnerText].Size;
                    fTile.EntityTexture = GlobalAssets.EntityTextures[tile["textureKey"].InnerText];
                    fTile.Colidable     = GlobalAssets.EntityTextures[tile["textureKey"].InnerText].Colidable;
                    this.Entity.Add(fTile);
                }
                else
                {
                    switch (tile["textureKey"].InnerText.TrimEnd('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'))
                    {
                    case "corphafon":
                        Corphafon fTile = new Corphafon();
                        fTile.X             = int.Parse(tile["position"]["x"].InnerText) * 64;
                        fTile.Y             = int.Parse(tile["position"]["y"].InnerText) * 64;
                        fTile.Texture       = GlobalAssets.EntityTextures[tile["textureKey"].InnerText].Texture;
                        fTile.Size          = GlobalAssets.EntityTextures[tile["textureKey"].InnerText].Size;
                        fTile.EntityTexture = GlobalAssets.EntityTextures[tile["textureKey"].InnerText];
                        fTile.Texture       = fTile.EntityTexture.Texture;
                        this.Entity.Add(fTile);
                        break;
                    }
                }
            }
        }
Example #31
0
        private void LoadTemplateFile(string path)
        {
            // Reset the lighting
            GameManager.Game.Penumbra.Lights.Clear();
            GameManager.Game.Player.InitLighting();
            GameManager.Game.Penumbra.Hulls.Clear();
            ((MainGameScreen)GameManager.Game.GameScreen).InitLighting();

            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load(path);

            foreach (XmlNode tile in xmlDocument["world"]["tiles"])
            {
                // Add a tile to the colidable tiles layer
                Tile fTile = ParseTile(tile);

                fTile.TileInfo.Tile = fTile;
                WorldTemplate.ParseTemplateTag(fTile);
                this.Tiles.Add(fTile);
            }
            foreach (XmlNode tile in xmlDocument["world"]["floorTiles"])
            {
                // Add a tile to the floor layer
                this.FloorTiles.Add(ParseTile(tile));
            }
            foreach (XmlNode tile in xmlDocument["world"]["decor"])
            {
                //Custom entitity tiles
                if (tile["textureKey"].InnerText == "torch")
                {
                    // Torch

                    Torch torch = new Torch();
                    torch.X = int.Parse(tile["position"]["x"].InnerText) * 64;
                    torch.Y = int.Parse(tile["position"]["y"].InnerText) * 64;
                    Entity.Add(torch);
                    GameManager.Game.Penumbra.Lights.Add(new PointLight
                    {
                        Position     = new Vector2(torch.X + 32, torch.Y + 32),
                        Scale        = new Vector2(600),
                        ShadowType   = ShadowType.Illuminated,
                        CastsShadows = true,
                        Intensity    = 0.5f
                    });
                }
                else
                {
                    // Normal entity-tile
                    Tile fTile = ParseTile(tile);
                    this.Decor.Add(fTile);
                }
            }
            foreach (XmlNode tile in xmlDocument["world"]["entitys"])
            {
                if (GlobalAssets.EntityTextures[tile["textureKey"].InnerText].IsTile)
                {
                    TileEntity fTile = new TileEntity(new Frame(GlobalAssets.EntityTextures[tile["textureKey"].InnerText].Texture));
                    fTile.X             = int.Parse(tile["position"]["x"].InnerText) * 64;
                    fTile.Y             = int.Parse(tile["position"]["y"].InnerText) * 64;
                    fTile.Texture       = GlobalAssets.EntityTextures[tile["textureKey"].InnerText].Texture;
                    fTile.Size          = GlobalAssets.EntityTextures[tile["textureKey"].InnerText].Size;
                    fTile.EntityTexture = GlobalAssets.EntityTextures[tile["textureKey"].InnerText];
                    fTile.Colidable     = GlobalAssets.EntityTextures[tile["textureKey"].InnerText].Colidable;
                    this.Entity.Add(fTile);

                    fTile.AfterAdd();
                }
                else
                {
                    switch (tile["textureKey"].InnerText.TrimEnd('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'))
                    {
                    case "corphafon":
                        Corphafon fTile = new Corphafon();
                        fTile.X             = int.Parse(tile["position"]["x"].InnerText) * 64;
                        fTile.Y             = int.Parse(tile["position"]["y"].InnerText) * 64;
                        fTile.Texture       = GlobalAssets.EntityTextures[tile["textureKey"].InnerText].Texture;
                        fTile.Size          = GlobalAssets.EntityTextures[tile["textureKey"].InnerText].Size;
                        fTile.EntityTexture = GlobalAssets.EntityTextures[tile["textureKey"].InnerText];
                        fTile.Texture       = fTile.EntityTexture.Texture;
                        this.Entity.Add(fTile);
                        fTile.AfterAdd();
                        break;
                    }
                }
            }
        }
Example #32
0
 public BCMTileEntity(Vector3i pos, [NotNull] TileEntity te)
 {
     Type = te.GetTileEntityType().ToString();
     Pos  = new BCMVector3(pos);
 }
    // Update is called once per frame
    void Update()
    {
        if (hasSword)
        {
            hasSword = false;
            damage   = 20;
        }
        if (targetCoord2.x != 0 || targetCoord2.y != 0)
        {
            if (targetCoord2.y > tile.y)
            {
                orientation        = Direction.NORTH;
                transform.position = new Vector3(transform.position.x, transform.position.y + 1, 0);
            }
            else if (targetCoord2.x < tile.x)
            {
                orientation        = Direction.WEST;
                transform.position = new Vector3(transform.position.x - 1, transform.position.y, 0);
            }
            else if (targetCoord2.y < tile.y)
            {
                orientation        = Direction.SOUTH;
                transform.position = new Vector3(transform.position.x, transform.position.y - 1, 0);
            }
            else if (targetCoord2.x > tile.x)
            {
                orientation        = Direction.EAST;
                transform.position = new Vector3(transform.position.x + 1, transform.position.y, 0);
            }
            OnMove();
            transform.eulerAngles = new Vector3(0, 0, 180 - ((int)orientation * 90));
            if (targetCoord2.x == tile.x && targetCoord2.y == tile.y)
            {
                TileEntity te = GameObject.Find("Pnj (Dadghost)").GetComponent <TileEntity> ();
                te.tile.entity        = null;
                te.tile               = World.instance.GetTile(20, 91);
                te.transform.position = te.tile.transform.position;
                te.tile.entity        = te;
                transform.eulerAngles = new Vector3(0, 0, 180 - ((int)Direction.SOUTH * 90));
                GameObject.Find("Canvas").GetComponent <UIManager> ().lockBS = false;
                if (compteurBidon > 0)
                {
                    GameObject.Find("Canvas").GetComponent <UIManager> ().SetAlpha(compteurBidon);
                    compteurBidon--;
                    return;
                }
                targetCoord2 = new Vector2(0, 0);
                QuestManager.Instance.indexQuest = 14;
            }
            return;
        }

        if (targetCoord.x != 0 || targetCoord.y != 0)
        {
            if (compteurBidon < 100)
            {
                GameObject.Find("Canvas").GetComponent <UIManager> ().SetAlpha(compteurBidon);
                compteurBidon++;
                return;
            }
            GameObject.Find("Canvas").GetComponent <UIManager> ().lockBS = true;
            if (targetCoord.y > tile.y)
            {
                orientation        = Direction.NORTH;
                transform.position = new Vector3(transform.position.x, transform.position.y + 1, 0);
            }
            else if (targetCoord.x < tile.x)
            {
                orientation        = Direction.WEST;
                transform.position = new Vector3(transform.position.x - 1, transform.position.y, 0);
            }
            else if (targetCoord.y < tile.y)
            {
                orientation        = Direction.SOUTH;
                transform.position = new Vector3(transform.position.x, transform.position.y - 1, 0);
            }
            else if (targetCoord.x > tile.x)
            {
                orientation        = Direction.EAST;
                transform.position = new Vector3(transform.position.x + 1, transform.position.y, 0);
            }
            world.MoveWorld(orientation);
            OnMove();
            for (int i = 0; i < World.width; i++)
            {
                for (int j = 0; j < World.height; j++)
                {
                    world.GetTile(i, j).OnPlayerMove(tile.x, tile.y);
                }
            }
            transform.eulerAngles = new Vector3(0, 0, 180 - ((int)orientation * 90));
            if (targetCoord.x == tile.x && targetCoord.y == tile.y)
            {
                targetCoord = new Vector2(0, 0);
                QuestManager.Instance.indexQuest = 13;
                targetCoord2 = new Vector2(20, 93);
            }
            return;
        }

        if (moveText.Length > 0)
        {
            if (Time.time < time + 0.5f)
            {
                return;
            }
            time = Time.time;
            switch (moveText [0])
            {
            case 'z':
                orientation = Direction.NORTH;
                tilePos     = world.GetTile(tile.x, (tile.y >= World.height - 1 ? -1 : tile.y) + 1);
                if (tilePos.IsWalkable())
                {
                    transform.position = new Vector3(transform.position.x, transform.position.y + 1, 0);
                    moveText           = moveText.Remove(0, 1);
                    world.MoveWorld(Direction.NORTH);
                }
                break;

            case 'd':
                orientation = Direction.EAST;
                tilePos     = world.GetTile((tile.x >= World.width - 1 ? -1 : tile.x) + 1, tile.y);
                if (tilePos.IsWalkable())
                {
                    transform.position = new Vector3(transform.position.x + 1, transform.position.y, 0);
                    moveText           = moveText.Remove(0, 1);
                    world.MoveWorld(Direction.EAST);
                }
                break;

            case 's':
                orientation = Direction.SOUTH;
                tilePos     = world.GetTile(tile.x, (tile.y <= 0 ? World.height : tile.y) - 1);
                if (tilePos.IsWalkable())
                {
                    transform.position = new Vector3(transform.position.x, transform.position.y - 1, 0);
                    moveText           = moveText.Remove(0, 1);
                    world.MoveWorld(Direction.SOUTH);
                }
                break;

            case 'q':
                orientation = Direction.WEST;
                tilePos     = world.GetTile((tile.x <= 0 ? World.width : tile.x) - 1, tile.y);
                if (tilePos.IsWalkable())
                {
                    transform.position = new Vector3(transform.position.x - 1, transform.position.y, 0);
                    moveText           = moveText.Remove(0, 1);
                    world.MoveWorld(Direction.WEST);
                }
                break;

            default:
                moveText = moveText.Remove(0, 1);
                break;
            }
            OnMove();
            for (int i = 0; i < World.width; i++)
            {
                for (int j = 0; j < World.height; j++)
                {
                    world.GetTile(i, j).OnPlayerMove(tile.x, tile.y);
                }
            }
            transform.eulerAngles = new Vector3(0, 0, 180 - ((int)orientation * 90));
            return;
        }


        if (Input.GetKeyDown(KeyCode.E) && tilePos && tilePos.entity != null)
        {
            if (orientation == Direction.NORTH)
            {
                tilePos = world.GetTile(tile.x, (tile.y >= World.height - 1 ? -1 : tile.y) + 1);
            }
            else if (orientation == Direction.WEST)
            {
                tilePos = world.GetTile((tile.x <= 0 ? World.width : tile.x) - 1, tile.y);
            }
            else if (orientation == Direction.SOUTH)
            {
                tilePos = world.GetTile(tile.x, (tile.y <= 0 ? World.height : tile.y) - 1);
            }
            else if (orientation == Direction.EAST)
            {
                tilePos = world.GetTile((tile.x >= World.width - 1 ? -1 : tile.x) + 1, tile.y);
            }
            if (tilePos && tilePos.entity != null)
            {
                tilePos.entity.Action(this);
            }
        }
        if (Input.GetKeyDown(KeyCode.F) && tilePos && tilePos.entity != null && tilePos.entity != this)
        {
            if (orientation == Direction.NORTH)
            {
                tilePos = world.GetTile(tile.x, (tile.y >= World.height - 1 ? -1 : tile.y) + 1);
            }
            else if (orientation == Direction.WEST)
            {
                tilePos = world.GetTile((tile.x <= 0 ? World.width : tile.x) - 1, tile.y);
            }
            else if (orientation == Direction.SOUTH)
            {
                tilePos = world.GetTile(tile.x, (tile.y <= 0 ? World.height : tile.y) - 1);
            }
            else if (orientation == Direction.EAST)
            {
                tilePos = world.GetTile((tile.x >= World.width - 1 ? -1 : tile.x) + 1, tile.y);
            }
            if (tilePos && tilePos.entity != null && tilePos.entity != this)
            {
                Attack(tilePos.entity);
            }
        }
        bool move = true;

        if (Time.time < time + actualSpeed || blockMoving)
        {
            return;
        }
        if (Time.time > foodTime + foodSpeed)
        {
            foodTime = Time.time;
            QuestManager.Instance.DecreaseFood(0.2f);
            float dg = QuestManager.Instance.playerFood / 100.0f;
            if (QuestManager.Instance.playerKarma < 0 && dg < 0)
            {
                dg *= 20f;
            }
            Heal(dg);
            GameObject.Find("Canvas").GetComponent <UIManager> ().UpdateFoodText(dg);
        }
        if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.Z))
        {
            orientation = Direction.NORTH;
            tilePos     = world.GetTile(tile.x, (tile.y >= World.height - 1 ? -1 : tile.y) + 1);
            if (tilePos.IsWalkable())
            {
                transform.position = new Vector3(transform.position.x, transform.position.y + 1, 0);
                if (QuestManager.Instance.indexQuest < 14)
                {
                    world.MoveWorld(Direction.NORTH);
                }
            }
        }
        else if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.Q))
        {
            orientation = Direction.WEST;
            tilePos     = world.GetTile((tile.x <= 0 ? World.width : tile.x) - 1, tile.y);
            if (tilePos.IsWalkable())
            {
                transform.position = new Vector3(transform.position.x - 1, transform.position.y, 0);
                if (QuestManager.Instance.indexQuest < 14)
                {
                    world.MoveWorld(Direction.WEST);
                }
            }
        }
        else if (Input.GetKey(KeyCode.S))
        {
            orientation = Direction.SOUTH;
            tilePos     = world.GetTile(tile.x, (tile.y <= 0 ? World.height : tile.y) - 1);
            if (tilePos.IsWalkable())
            {
                transform.position = new Vector3(transform.position.x, transform.position.y - 1, 0);
                if (QuestManager.Instance.indexQuest < 14)
                {
                    world.MoveWorld(Direction.SOUTH);
                }
            }
        }
        else if (Input.GetKey(KeyCode.D))
        {
            orientation = Direction.EAST;
            tilePos     = world.GetTile((tile.x >= World.width - 1 ? -1 : tile.x) + 1, tile.y);
            if (tilePos.IsWalkable())
            {
                transform.position = new Vector3(transform.position.x + 1, transform.position.y, 0);
                if (QuestManager.Instance.indexQuest < 14)
                {
                    world.MoveWorld(Direction.EAST);
                }
            }
        }
        else
        {
            move = false;
        }
        if (move)
        {
            actualSpeed = speed;
            time        = Time.time;
            if (QuestManager.Instance.indexQuest < 14)
            {
                for (int i = 0; i < World.width; i++)
                {
                    for (int j = 0; j < World.height; j++)
                    {
                        world.GetTile(i, j).OnPlayerMove(tile.x, tile.y);
                    }
                }
            }
            if (tilePos.entity != null)
            {
                tilePos.entity.Push(orientation);
            }
            transform.eulerAngles = new Vector3(0, 0, 180 - ((int)orientation * 90));
            OnMove();
            if (tile.GetComponent <MeshRenderer> () == null)
            {
                return;
            }
            switch (tile.GetComponent <MeshRenderer> ().material.name.Split(' ')[0])
            {
            case "Sand":
                actualSpeed += 0.4f;
                break;

            case "Herbe":
                actualSpeed += 0.1f;
                break;

            case "HerbeSpecial":
                actualSpeed += 0.1f;
                break;

            case "Champs":
                actualSpeed += 0.2f;
                break;

            case "Route":
                actualSpeed -= 0.050f;
                break;

            case "Water":
                actualSpeed += 0.4f;
                break;

            case "Rail":
                actualSpeed += 0.5f;
                break;
            }
        }
    }
Example #34
0
    /// <summary>
    /// 计算目标的伤害值(伤害公式)
    /// </summary>
    /// <param name="targeterModel"></param>
    /// <param name="attackerModel"></param>
    /// <param name="attacker">技能道具等情况下 attacker 为 null </param>
    /// <param name="factor">伤害修正系数</param>
    /// <returns></returns>
    private static float CalcDamageValue(EntityModel targeterModel, EntityModel attackerModel, TileEntity attacker = null, float factor = 1.0f)
    {
        float damage = 0.0f;

        if (EntityTypeUtil.IsCurer(attackerModel))
        {
            //  回血为负
            damage = -factor * attackerModel.cure;
        }
        else
        {
            //  REMARK:伤害公式可以调整
            damage = attackerModel.damage - targeterModel.defense;
            if (attackerModel.additionDamageSubType != Constants.EMPTY && attackerModel.additionDamageSubType == targeterModel.subType)
            {
                damage *= attackerModel.additionDamageRatio;
            }

            //  技能伤害的时候 attacker 不存在
            if (attacker != null)
            {
                //  [攻击提升] buffer 的情况下乘以伤害倍率
                GameBufferComponent attackerBufferMgr = attacker.GetComponent <GameBufferComponent>();
                if (attackerBufferMgr != null)
                {
                    var buffer = attackerBufferMgr.GetBuffer(Constants.BUFF_TYPE_ATTACKUP);
                    if (buffer != null)
                    {
                        damage *= buffer.buffDamage;
                    }
                }
            }

            damage = Mathf.Max(damage * factor, 0);
        }

        //  处理伤害
        return(damage);
    }
Example #35
0
 public override UnitEntity GetTargetFromSelectedTile(UnitEntity caster, TileEntity tile)
 {
     return(GetEnemyUnitFromTile(caster, tile));
 }
Example #36
0
        public virtual void emptyBagOnMagicStorage(Player p, int x, int y)
        {
            Mod magicStorage = ModLoader.GetMod("MagicStorage");

            if (magicStorage != null)
            {
                try
                {
                    if (Main.tile[x, y].frameX % 36 == 18)
                    {
                        x--;
                    }
                    if (Main.tile[x, y].frameY % 36 == 18)
                    {
                        y--;
                    }
                    ModTile    t        = TileLoader.GetTile(Main.tile[x, y].type);
                    MethodInfo getHeart = (t.GetType()).GetMethod("GetHeart", BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(int), typeof(int) }, null);
                    if (getHeart == null)
                    {
                        BagsOfHoldingMod.debugChat("GetHeart() is null. Report to author.");
                        ErrorLogger.Log("GetHeart() is null on " + (Main.netMode == NetmodeID.MultiplayerClient ? "client" : "server"));
                        return;
                    }
                    object[] param = new object[2];
                    param[0] = x;
                    param[1] = y;
                    TileEntity heart = (TileEntity)getHeart.Invoke(t, param);
                    if (heart == null)
                    {
                        BagsOfHoldingMod.sendChat("This Access does not have an associated Storage Heart.");
                        return;
                    }
                    Type[] depCal = new Type[1];
                    depCal[0] = typeof(Item);
                    MethodInfo deposit = heart.GetType().GetMethod("DepositItem", BindingFlags.Public | BindingFlags.Instance, null, depCal, null);
                    if (deposit == null)
                    {
                        BagsOfHoldingMod.debugChat("DepositItem(Item) is null. Report to author.");
                        ErrorLogger.Log("DepositItem(Item) is null on " + (Main.netMode == NetmodeID.MultiplayerClient ? "client" : "server"));
                        return;
                    }

                    for (int i = 0; i < order.Count; i++)
                    {
                        if (items.ContainsKey(order[i]))
                        {
                            long remain         = items.GetAsLong(order[i]);
                            bool prematureBreak = false;
                            while (remain > 0 && !prematureBreak)
                            {
                                Item itm       = getItemFromTag(order[i]);
                                int  stackSize = (int)Math.Min(remain, itm.maxStack);
                                itm.stack = stackSize;
                                deposit.Invoke(heart, new object[] { itm });
                                if (itm.IsAir)
                                {
                                    remain -= stackSize;
                                }
                                else
                                {
                                    remain        -= (stackSize - itm.stack);
                                    prematureBreak = true;
                                }
                            }
                            items.Remove(order[i]);
                            if (remain > 0)
                            {
                                items[order[i]] = remain;
                            }
                        }
                    }
                }catch (Exception e)
                {
                    BagsOfHoldingMod.debugChat(e.ToString());
                }
                if (Main.netMode == NetmodeID.MultiplayerClient)
                {
                    ModPacket pack = mod.GetPacket();
                    pack.Write((byte)2);
                    pack.Write((byte)p.whoAmI);
                    pack.Write((byte)p.selectedItem);
                    TagIO.Write(items, pack);
                    pack.Send();
                }
            }
        }
Example #37
0
 /// <summary>
 /// 被添加到建筑小屋中
 /// </summary>
 /// <param name="workerHouse"></param>
 public void OnAddToWorkerHouse(TileEntity workerHouse)
 {
     _workerHouse = workerHouse;
 }
Example #38
0
 /// <summary>
 /// Sets a new Tile Entity record for the block.
 /// </summary>
 /// <param name="te">A Tile Entity record compatible with the block's type.</param>
 public void SetTileEntity(TileEntity te)
 {
     _collection.SetTileEntity(_index, te);
 }
Example #39
0
 public void renewMiniMap(DungeonInformation dginfo, TileEntity[] tiles)
 {
     CurrentMiniMap = new MiniMap(dginfo, tiles);
 }
Example #40
0
 TileEntity getTile(Vector2 pos)
 {
     if(Tile ==null) Tile = GameController.getTileEntity(pos);
     return Tile;
 }
Example #41
0
 public SpawnerEditor(TileEntity e)
 {
     InitializeComponent();
     TileEntity = e;
 }
        public void OnTileEntityChanged(TileEntity _te, int _dataObject)
        {
            if (_te is TileEntityWorkstation)
            {
//				TileEntityWorkstation ws = _te as TileEntityWorkstation;
//				bool isChanged = false;
//				if (ws.IsBurning != isBurning) {
//					SDTM.API.Events.NotifyWorkstationIsActiveChangedHandlers (ws, isBurning, ws.IsBurning);
//					isChanged = true;
//				}
//
//				if (ws.BurnTotalTimeLeft != totalBurnTimeLeft) {
//					SDTM.API.Events.NotifyWorkstationTotalBurnTimeChangedHandlers (ws, totalBurnTimeLeft, ws.BurnTotalTimeLeft);
//					isChanged = true;
//				}
//
//				if (ws.BurnTimeLeft != burnTimeLeft) {
//					SDTM.API.Events.NotifyWorkstationTotalBurnTimeChangedHandlers (ws, burnTimeLeft, ws.BurnTimeLeft);
//					isChanged = true;
//				}
//
//				for (int i = 0; i < ws.Tools.Length; i++) {
//					ItemStack wsTool = ws.Tools [i];
//					KeyValuePair<int, int> tool = tools [i];
//					if (tool.Key != wsTool.itemValue.type) {
//						ItemStack oldItem = new ItemStack (new ItemValue (tool.Key), tool.Value);
//						SDTM.API.Events.NotifyWorkstationToolChangedHandlers (ws, i, oldItem, wsTool);
//						isChanged = true;
//					} else {
//						if (tool.Value != wsTool.count) {
//							ItemStack oldItem = new ItemStack (new ItemValue (tool.Key), tool.Value);
//							SDTM.API.Events.NotifyWorkstationToolChangedHandlers (ws, i, oldItem, wsTool);
//							isChanged = true;
//						}
//					}
//				}
//
//				for (int i = 0; i < ws.Fuel.Length; i++) {
//					ItemStack wsFuel = ws.Fuel [i];
//					KeyValuePair<int, int> fuelItem = fuel [i];
//					if (fuelItem.Key != wsFuel.itemValue.type) {
//						ItemStack oldItem = new ItemStack (new ItemValue (fuelItem.Key), fuelItem.Value);
//						SDTM.API.Events.NotifyWorkstationFuelChangedHandlers (ws, i, oldItem, wsFuel);
//						isChanged = true;
//					} else {
//						if (fuelItem.Value != wsFuel.count) {
//							ItemStack oldItem = new ItemStack (new ItemValue (fuelItem.Key), fuelItem.Value);
//							SDTM.API.Events.NotifyWorkstationFuelChangedHandlers (ws, i, oldItem, wsFuel);
//							isChanged = true;
//						}
//					}
//				}
//
//				for (int i = 0; i < ws.Input.Length-ws.MaterialNames.Length; i++) {
//					ItemStack wsInput = ws.Input [i];
//					KeyValuePair<int, int> inputItem = input [i];
//					if (inputItem.Key != wsInput.itemValue.type) {
//						ItemStack oldItem = new ItemStack (new ItemValue (inputItem.Key), inputItem.Value);
//						SDTM.API.Events.NotifyWorkstationInputChangedHandlers (ws, i, oldItem, wsInput);
//						isChanged = true;
//					} else {
//						if (inputItem.Value != wsInput.count) {
//							ItemStack oldItem = new ItemStack (new ItemValue (inputItem.Key), inputItem.Value);
//							SDTM.API.Events.NotifyWorkstationInputChangedHandlers (ws, i, oldItem, wsInput);
//							isChanged = true;
//						}
//					}
//				}
//
//				for (int i = 0; i < ws.Output.Length; i++) {
//					ItemStack wsOutput = ws.Output [i];
//					KeyValuePair<int, int> outputItem = output [i];
//					if (outputItem.Key != wsOutput.itemValue.type) {
//						ItemStack oldItem = new ItemStack (new ItemValue (outputItem.Key), outputItem.Value);
//						SDTM.API.Events.NotifyWorkstationOutputChangedHandlers (ws, i, oldItem, wsOutput);
//						isChanged = true;
//					} else {
//						if (outputItem.Value != wsOutput.count) {
//							ItemStack oldItem = new ItemStack (new ItemValue (outputItem.Key), outputItem.Value);
//							SDTM.API.Events.NotifyWorkstationOutputChangedHandlers (ws, i, oldItem, wsOutput);
//							isChanged = true;
//						}
//					}
//				}
//
//				if (isChanged) {
//					SetHistory (ws);
//				}
            }
        }
 public void changeTileTypeInTable(TileEntity tile,bool recreateminimap)
 {
     if (CurrentFloor.FloorRect.Contains(tile.Position)) {
         int x = (int)tile.Position.x;
         int y = (int)tile.Position.y;
         //Debug.logger.Log(tile.Position.ToString(),tile.Type);
         TileTypeTable[x][y] = tile.Type;
         if (recreateminimap) {
             GameController.MiniMap.CurrentMiniMap.recreateMiniMapTexture();
         }
     }
 }
Example #44
0
 public BuildAction(MovingEntity movingEntity, TileEntity target, GameObject buildPrefab)
 {
     this.movingEntity = movingEntity;
     this.target       = target;
     this.buildPrefab  = buildPrefab;
 }
Example #45
0
        public static bool Postfix(bool ___result, TileEntity __instance, World world)
        {
            BlockValue block          = GameManager.Instance.World.GetBlock(__instance.ToWorldPos());
            Block      block2         = Block.list[block.type];
            bool       isAlwaysActive = false;

            if (block2.Properties.Values.ContainsKey("AlwaysActive"))
            {
                isAlwaysActive = StringParsers.ParseBool(block2.Properties.Values["AlwaysActive"], 0, -1, true);
                if (isAlwaysActive)
                {
                    ___result = true;
                    AdvLogging.DisplayLog(AdvFeatureClass, block2.GetBlockName() + ": TileEntity is Active.");
                    bool blCanTrigger = false;

                    int Bounds = 6;
                    if (block2.Properties.Values.ContainsKey("ActivationDistance"))
                    {
                        Bounds = StringParsers.ParseSInt32(block2.Properties.Values["ActivationDistance"].ToString());
                    }

                    // Scan for the player in the radius as defined by the Activation distance of the block
                    List <Entity> entitiesInBounds = GameManager.Instance.World.GetEntitiesInBounds(null, new Bounds(__instance.ToWorldPos().ToVector3(), (Vector3.one * 20)));
                    if (entitiesInBounds.Count > 0)
                    {
                        AdvLogging.DisplayLog(AdvFeatureClass, block2.GetBlockName() + ": TileEntity has Entities in Bound of " + Bounds);
                        for (int i = 0; i < entitiesInBounds.Count; i++)
                        {
                            EntityPlayer player = entitiesInBounds[i] as EntityPlayer;
                            if (player)
                            {
                                float distance = (player.position - __instance.ToWorldPos().ToVector3()).sqrMagnitude;
                                if (distance > block2.GetActivationDistanceSq())
                                {
                                    continue;
                                }

                                AdvLogging.DisplayLog(AdvFeatureClass, block2.GetBlockName() + ": Player: " + player.EntityName + " is in bounds");

                                if (block2.Properties.Values.ContainsKey("ActivationBuffs"))
                                {
                                    foreach (String strbuff in block2.Properties.Values["ActivationBuffs"].Split(','))
                                    {
                                        AdvLogging.DisplayLog(AdvFeatureClass, block2.GetBlockName() + ": Checking ActivationBuffs: " + strbuff);
                                        String strBuffName = strbuff;
                                        float  CheckValue  = -1f;

                                        // Check if there's a ( ) at the end of the buff; this will be used as a cvar hook.
                                        int start = strbuff.IndexOf('(');
                                        int end   = strbuff.IndexOf(')');
                                        if (start != -1 && end != -1 && end > start + 1)
                                        {
                                            CheckValue  = StringParsers.ParseFloat(strbuff.Substring(start + 1, end - start - 1), 0, -1, NumberStyles.Any);
                                            strBuffName = strbuff.Substring(0, start);
                                            AdvLogging.DisplayLog(AdvFeatureClass, block2.GetBlockName() + ": Actviation Buff is a cvar: " + strBuffName + ". Requires value: " + CheckValue);
                                        }

                                        // If the player has a buff by this name, trigger it.
                                        if (player.Buffs.HasBuff(strBuffName))
                                        {
                                            AdvLogging.DisplayLog(AdvFeatureClass, block2.GetBlockName() + ": Buff has been found: " + strBuffName);
                                            blCanTrigger = true;
                                        }

                                        // If the player has a cvar, then do some extra checks
                                        if (player.Buffs.HasCustomVar(strBuffName))
                                        {
                                            AdvLogging.DisplayLog(AdvFeatureClass, block2.GetBlockName() + ": Cvar has been found: " + strBuffName);
                                            // If there's no cvar value specified, just allow it.
                                            if (CheckValue == -1)
                                            {
                                                AdvLogging.DisplayLog(AdvFeatureClass, block2.GetBlockName() + ": Cvar found, and does not require a specific value.");
                                                blCanTrigger = true;
                                            }
                                            // If a cvar is set, then check to see if it matches
                                            if (CheckValue > -1)
                                            {
                                                AdvLogging.DisplayLog(AdvFeatureClass, block2.GetBlockName() + ": Cvar found, and requires a value of " + CheckValue + " Player has: " + player.Buffs.GetCustomVar(strBuffName));
                                                if (player.Buffs.GetCustomVar(strBuffName) == CheckValue)
                                                {
                                                    blCanTrigger = true;
                                                }
                                            }

                                            // If any of these conditions match, trigger the Activate block
                                            if (blCanTrigger)
                                            {
                                                AdvLogging.DisplayLog(AdvFeatureClass, block2.GetBlockName() + ":  Checks successfully passed for player: " + player.EntityName);
                                                break;
                                            }
                                            else
                                            {
                                                AdvLogging.DisplayLog(AdvFeatureClass, block2.GetBlockName() + ": Checks were NOT success for player: " + player.EntityName);
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    blCanTrigger = true;
                                }

                                if (blCanTrigger)
                                {
                                    break;
                                }
                            }
                        }
                    }

                    if (blCanTrigger)
                    {
                        AdvLogging.DisplayLog(AdvFeatureClass, block2.GetBlockName() + ": TileEntity can call ActivateBlock. Calling it...");
                        Block.list[block.type].ActivateBlock(world, __instance.GetClrIdx(), __instance.ToWorldPos(), block, true, true);
                    }
                    else
                    {
                        AdvLogging.DisplayLog(AdvFeatureClass, block2.GetBlockName() + ": TileEntity is Active but is not Activating.");
                        Block.list[block.type].ActivateBlock(world, __instance.GetClrIdx(), __instance.ToWorldPos(), block, false, true);
                    }
                    return(true);
                }
            }
            return(false);
        }
Example #46
0
 public InteractAction(MovingEntity movingEntity, TileEntity target, bool isPrimary)
 {
     this.movingEntity = movingEntity;
     this.target       = target;
     this.isPrimary    = isPrimary;
 }
Example #47
0
 /// <inheritdoc/>
 public void SetTileEntity(int x, int y, int z, TileEntity te)
 {
     _tileEntityManager.SetTileEntity(x, y, z, te);
     _dirty = true;
 }
 public TileEntityEnchantmentTable (TileEntity te)
     : base(te)
 {
 }
 public static TileEntity[] getAllTiles()
 {
     TileEntity[] tiles = new TileEntity[Tiles.childCount];
     int i = 0;
     foreach (Transform c in Tiles.transform)
     {
         tiles[i++] = c.GetComponent<TileEntity>();
     }
     return tiles;
 }
Example #50
0
 // Returns true on a success
 public bool RemoveEngagedEnemy(TileEntity tar)
 {
     return(engagedEnemies.Remove(tar));
 }
Example #51
0
    /// <summary>
    /// 对单个目标进行伤害处理
    /// </summary>
    /// <param name="targeter"></param>
    /// <param name="attackerModel"></param>
    /// <param name="attacker">技能道具等情况下 attacker 为 null </param>
    /// <param name="factor"></param>
    public static void ProcessDamageOneTargeter(TileEntity targeter, EntityModel attackerModel, TileEntity attacker = null, float factor = 1.0f)
    {
        if (!targeter.IsDead())
        {
            //  计算伤害
            float damage = CalcDamageValue(targeter.model, attackerModel, attacker, factor);

            //  处理伤害
            targeter.MakeDamage(damage);

            //  没死亡时附加buffer效果
            if (!targeter.IsDead())
            {
                GameBufferComponent bufferMgr = targeter.GetComponent <GameBufferComponent>();
                if (bufferMgr != null)
                {
                    bufferMgr.AddBuffer(attackerModel);
                }
            }
            else
            {
                //  [特殊技能] 死亡后大回复
                if (EntityTypeUtil.IsTraitBlessing(targeter.model))
                {
                    //  TODO:
                }
            }

            //  [特殊技能] 吸血   REMARK:考虑是否需要回血光效?
            if (attacker != null && damage > 0 && EntityTypeUtil.IsTraitSuckBlood(attackerModel))
            {
                attacker.MakeDamage(-damage * Constants.SUCK_BLOOD_RATIO);
            }
        }
    }
Example #52
0
        internal void SetTileEntity(int index, TileEntity te)
        {
            int x, y, z;
            _blocks.GetMultiIndex(index, out x, out y, out z);

            _tileEntityManager.SetTileEntity(x, y, z, te);
            _dirty = true;
        }
Example #53
0
 public void AddEngagedEnemy(TileEntity tar)
 {
     Debug.Log("Enemy is attacking");
     engagedEnemies.Add(tar);
 }
Example #54
0
        public override bool PreDraw(int i, int k, SpriteBatch spriteBatch)
        {
            Tile tile = Main.tile[i, k];

            if (tile.active() && tile.type == mod.TileType("ItemDuctTile"))
            {
                TileEntity tileEntity = default(TileEntity);

                if (TileEntity.ByPosition.TryGetValue(new Point16(i, k), out tileEntity))
                {
                    TEItemDuct es = tileEntity as TEItemDuct;

                    // draw connectors

                    Tile uTile = Framing.GetTileSafely(i, k - 1);
                    Tile dTile = Framing.GetTileSafely(i, k + 1);
                    Tile lTile = Framing.GetTileSafely(i - 1, k);
                    Tile rTile = Framing.GetTileSafely(i + 1, k);

                    bool uCon = es.SpecialConnects(uTile, i, k - 1);
                    bool dCon = es.SpecialConnects(dTile, i, k + 1);
                    bool lCon = es.SpecialConnects(lTile, i - 1, k);
                    bool rCon = es.SpecialConnects(rTile, i + 1, k);

                    if (uCon || dCon || lCon || rCon)
                    {
                        bool[] con = new bool[] { uCon, dCon, lCon, rCon };

                        Color lightCol = Lighting.GetColor(i, k);

                        //TODO: why does the spritebatch seem to draw offset 12 tiles to the -x and -y?
                        int oi = i;
                        int ok = k;

                        i += 12;
                        k += 12;

                        int tfrX = es.flowItems.Count > 0 ? 1 : 0;
                        int frY  = 0;

                        switch (es.ductType)
                        {
                        case TEItemDuct.DuctType.In:
                            frY = 15 * 18;
                            break;

                        case TEItemDuct.DuctType.Out:
                            frY = 15 * 18 + 34;
                            break;

                        case TEItemDuct.DuctType.None:
                        default:
                            break;
                        }

                        Texture2D texture = (!Main.canDrawColorTile(tile.type, tile.color())) ? Main.tileTexture[tile.type] : Main.tileAltTexture[tile.type, tile.color()];
                        Vector2   start   = new Vector2((float)(i * 16 - (32 - 16) / 2 + 16), (float)(k * 16 - (32 - 16) / 2 + 16));
                        for (int d = 0; d < con.Length; d++)
                        {
                            if (!con[d])
                            {
                                continue;
                            }

                            float angle = new float[] { 0, 180, 270, 90 }[d];
                            spriteBatch.End();
                            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive);
                            spriteBatch.Draw(texture, start - Main.screenPosition, new Rectangle(tfrX * 34, frY, 32, 32), lightCol, angle * (float)(Math.PI / 180), new Vector2(16, 16), 1f, SpriteEffects.None, 1f);
                            spriteBatch.End();
                            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);

                            if (d == 0)
                            {
                                Util.DrawWorldTile(spriteBatch, oi, ok - 1, 12 * 16, 12 * 16);
                            }
                            if (d == 1)
                            {
                                Util.DrawWorldTile(spriteBatch, oi, ok + 1, 12 * 16, 12 * 16);
                            }
                            if (d == 2)
                            {
                                Util.DrawWorldTile(spriteBatch, oi - 1, ok, 12 * 16, 12 * 16);
                            }
                            if (d == 3)
                            {
                                Util.DrawWorldTile(spriteBatch, oi + 1, ok, 12 * 16, 12 * 16);
                            }
                        }
                    }
                }
            }

            spriteBatch.End();
            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive);
            return(base.PreDraw(i, k, spriteBatch));
        }
Example #55
0
        public static bool CheckWorkstationForPower(TileEntity myTileEntity)
        {
            AdvLogging.DisplayLog(AdvFeatureClass, "Does Workstation have access to Fuel?");
            bool blNeedsPower = false;

            // Read the block properties whenever we check, since we don't really persists whether or not we need power.
            BlockValue block = GameManager.Instance.World.GetBlock(myTileEntity.ToWorldPos());
            Block block2 = Block.list[block.type];
            blNeedsPower = false;
            if (block2.Properties.Values.ContainsKey("RequirePower"))
                blNeedsPower = StringParsers.ParseBool(block2.Properties.Values["RequirePower"], 0, -1, true);

            AdvLogging.DisplayLog(AdvFeatureClass, "Require Power? : " + blNeedsPower);

            // Doesn't need any power, so don't check.
            if (blNeedsPower == false)
                return true;

            AdvLogging.DisplayLog(AdvFeatureClass, "Workstation requires power. Checking near by tile entities.");

            // Check the nearby chunks for Power source tile entities, and check if they are on.
            Vector3i blockPosition = myTileEntity.ToWorldPos();
            World world = GameManager.Instance.World;
            int num = World.toChunkXZ(blockPosition.x);
            int num2 = World.toChunkXZ(blockPosition.z);
            for (int i = -1; i < 2; i++)
            {
                for (int j = -1; j < 2; j++)
                {
                    Chunk chunk = (Chunk)world.GetChunkSync(num + j, num2 + i);
                    if (chunk != null)
                    {
                        DictionaryList<Vector3i, TileEntity> tileEntities = chunk.GetTileEntities();
                        for (int k = 0; k < tileEntities.list.Count; k++)
                        {
                            AdvLogging.DisplayLog(AdvFeatureClass, "\tDetected Tile Entity: " + tileEntities.list[k].ToString());
                            TileEntityPowerSource tileEntity = tileEntities.list[k] as TileEntityPowerSource;
                            if (tileEntity != null)
                            {
                                if (tileEntity.IsActive(world))
                                    AdvLogging.DisplayLog(AdvFeatureClass, "\tEntity is Avtive " + tileEntities.list[k].ToString());
                                if (tileEntity.IsOn)
                                {
                                    AdvLogging.DisplayLog(AdvFeatureClass, "\tTile Entity is On: " + tileEntities.list[k].ToString());
                                    float distanceSq = (blockPosition.ToVector3() - tileEntity.ToWorldPos().ToVector3()).sqrMagnitude;
                                    if (distanceSq <= 20 * 20)
                                    {
                                        AdvLogging.DisplayLog(AdvFeatureClass, myTileEntity.ToString() + " Found Power Source as Fuel with " + tileEntity.ToString());
                                        //myTileEntity.HasPowerSDX = true;
                                        return true;
                                    }
                                }
                                else
                                    AdvLogging.DisplayLog(AdvFeatureClass, "\tTile Entity is off: " + tileEntities.list[k].ToString());
                            }
                        }
                    }
                }
            }
            return false;
        }
Example #56
0
 /// <summary>
 /// Adds this tile entity/building to this tile. Fails if the tile already has a building/entity.
 /// </summary>
 /// <param name="position">Position of tile</param>
 /// <param name="building">The building to add to the tile.</param>
 /// <returns>If the operation was successful.</returns>
 public bool AddTileEntityToTile(Vector2Int position, TileEntity tileEnt)
 {
     return(AddTileEntityToTile(position.x, position.y, tileEnt));
 }
Example #57
0
 /// <summary>
 /// 对多个目标进行伤害处理
 /// </summary>
 /// <param name="targeters"></param>
 /// <param name="attackerModel"></param>
 /// <param name="attacker">技能道具等情况下 attacker 为 null </param>
 /// <param name="factor"></param>
 public static void ProcessDamageMultiTargeters(List <TileEntity> targeters, EntityModel attackerModel, TileEntity attacker = null, float factor = 1.0f)
 {
     foreach (var targeter in targeters)
     {
         ProcessDamageOneTargeter(targeter, attackerModel, attacker, factor);
     }
 }
Example #58
0
 private void AddTileEntityToWorldGrid(TileEntity tileEnt, int x, int y)
 {
     WorldGrid.GetTile(x, y).AddModelToTile(tileEnt);
 }
Example #59
0
        public FactoryBarrel(TileEntity te)
            : base(te)
        {
            FactoryBarrel tec = te as FactoryBarrel;
            if (tec != null) {

            }
            if (tec != null) {
                TagNodeCompound block;
                TagNode block1;
                TagNode blockid;
                TagNode blockdamage;
                TagNode blockcount;

                tec.Source.TryGetValue("item_type", out block1);

                block = block1.ToTagCompound();

                block.TryGetValue("id", out blockid);
                block.TryGetValue("Damage", out blockdamage);
                block.TryGetValue("Count", out blockcount);

                _items = new Item(blockid.ToTagInt().Data);
                _items.Damage = blockdamage.ToTagInt().Data;
                _items.Count = blockcount.ToTagInt().Data;

                //_items = tec._items.Copy();
            }
            else {
                _items = new Item();
            }
        }