Ejemplo n.º 1
0
 public void Kill()
 {
     KillInternal();
     GameManager.EntityManager.UnloadEntity(GetLoadedEntity());
     if (!Inventory.IsEmpty)
     {
         LootSack loot = new LootSack(Vec2i.FromVector3(GetLoadedEntity().transform.position));
         loot.GetInventory().AddAll(Inventory);
         GameManager.WorldManager.AddNewObject(loot);
     }
     GameManager.EventManager.InvokeNewEvent(new EntityDeath(this));
 }
Ejemplo n.º 2
0
    public void Kill()
    {
        KillInternal();
        IsAlive = false;
        EntityManager.Instance.UnloadEntity(GetLoadedEntity(), killEntity: true);
        if (!Inventory.IsEmpty)
        {
            LootSack loot = new LootSack(Vec2i.FromVector3(GetLoadedEntity().transform.position).AsVector3());
            loot.GetInventory().AddAll(Inventory);
            GameManager.WorldManager?.AddNewObject(loot);
        }

        EventManager.Instance.InvokeNewEvent(new EntityDeath(this));
        Debug.Log("Entity  " + this + " is killed");
    }
Ejemplo n.º 3
0
    public Inventory GetSecondInventory()
    {
        if (SecondInventory.Inventory == null)
        {
            Vec2i playerPos = Vec2i.FromVector2(Player.Position2);
            //Get current object on player position
            WorldObjectData currentSpace = GameManager.WorldManager.World.GetWorldObject(playerPos);
            if (currentSpace == null)
            {
                //if there is no object here, we create one
                LootSack lootsack = new LootSack(playerPos);
                GameManager.WorldManager.AddNewObject(lootsack);
                SecondInventory.SetInventory(lootsack.GetInventory());

                SecondInventory.gameObject.SetActive(true);

                return(SecondInventory.Inventory);
            }
            //If current tile is taken, we check all the surrounding tiles
            Vec2i[] surrounding = GameManager.WorldManager.World.EmptyTilesAroundPoint(playerPos);
            foreach (Vec2i v in surrounding)
            {
                WorldObjectData surSpace = GameManager.WorldManager.World.GetWorldObject(v);
                if (surSpace == null)
                {
                    //if there is no object here, we create one
                    LootSack lootsack = new LootSack(v);
                    GameManager.WorldManager.AddNewObject(lootsack);
                    SecondInventory.SetInventory(lootsack.GetInventory());

                    SecondInventory.gameObject.SetActive(true);

                    return(SecondInventory.Inventory);
                }
            }
            //If there is no space near, we return null
            return(null);
        }
        else
        {
            //If the inventory is not null, we add to it
            return(SecondInventory.Inventory);
        }
    }
Ejemplo n.º 4
0
    protected override void KillInternal()
    {
        //If no items, we do nothing
        if (Inventory.GetItems().Count == 0)
        {
            return;
        }

        LootSack lootSack = new LootSack(Vec2i.FromVector3(Position));

        foreach (ItemStack it in Inventory.GetItems())
        {
            lootSack.GetInventory().AddItemStack(it);
        }

        Vec2i pos = Vec2i.FromVector3(Position);

        GameManager.WorldManager.AddNewObject(lootSack);
    }
Ejemplo n.º 5
0
    public List <ChunkData> Generate(GenerationRandom genRan)
    {
        Vec2i tilebase = Shell.Position * World.ChunkSize;

        if (Shell.BanditCampLevel > 1 && Shell.Size.x > 3 && Shell.Size.z > 3)
        {
            //If this camp is large enough, generate a dungeon entrance.

            Vec2i localPos = new Vec2i(2, TileSize.z / 2 - 2);

            CaveDungeonEntrance entr = new CaveDungeonEntrance(tilebase + localPos, null, new WorldObjectMetaData(direction: new Vec2i(1, 0)));
            IMultiTileObjectChild[,] children = entr.GetChildren();
            Objects[localPos.x, localPos.z]   = entr;
            for (int x = 0; x < entr.Size.x; x++)
            {
                for (int z = 0; z < entr.Size.z; z++)
                {
                    if (x == 0 && z == 0)
                    {
                        continue;
                    }
                    Objects[localPos.x + x, localPos.z + z] = children[x, z] as WorldObjectData;
                }
            }
            Debug.Log("Generated Bandit Camp with Dungeon at " + this.Shell.Position, Debug.CHUNK_STRUCTURE_GENERATION);

            Shell.SetDungeonEntrance(entr);
            entr.SetChunkStructure(Shell);
        }
        else
        {
            Debug.Log("Generated Bandit Camp no Dungeon at " + this.Shell.Position, Debug.CHUNK_STRUCTURE_GENERATION);
        }

        Objects[11, 11] = new LootSack(tilebase + new Vec2i(11, 11));
        FinalLootChest  = Objects[11, 11] as IInventoryObject;

        for (int x = 0; x < TileSize.x; x++)
        {
            for (int z = 0; z < TileSize.z; z++)
            {
                if (x == 0)
                {
                    Objects[x, z] = new WoodSpikeWall(tilebase + new Vec2i(x, z));
                }
                if (z == 0)
                {
                    Objects[x, z] = new WoodSpikeWall(tilebase + new Vec2i(x, z));
                }
                if (x == TileSize.x - 1 && z < TileSize.z / 2 - 2 && z > TileSize.z / 2 + 2)
                {
                    Objects[x, z] = new WoodSpikeWall(tilebase + new Vec2i(x, z));
                }
                if (z == TileSize.z - 1)
                {
                    Objects[x, z] = new WoodSpikeWall(tilebase + new Vec2i(x, z));
                }
                Tiles[x, z] = Tile.DIRT.ID;
            }
        }

        EntityFaction banditFaction = new EntityFaction("Bandit_Camp");

        for (int x = 0; x < Shell.Size.x; x++)
        {
            for (int z = 0; z < Shell.Size.z; z++)
            {
                //Entity e = new Bandit();
                //e.SetPosition(tilebase + new Vec2i(x * World.ChunkSize + 5, z * World.ChunkSize + z + 3));
                //Shell.AddEntity(x, z, e);
                //e.SetEntityFaction(banditFaction);
            }
        }
        Entity e = new Bandit();

        e.SetPosition(tilebase + new Vec2i(2 * World.ChunkSize + 5, 2 * World.ChunkSize + 2 + 3));
        Shell.AddEntity(0, 0, e);
        e.SetEntityFaction(banditFaction);



        return(ToChunkData());
    }