Exemple #1
0
        public void RotateFactionTurn()
        {
            int num    = (int)ActiveFaction;
            int length = Enum.GetValues(typeof(EntityFaction)).Length;

            if (num == length)
            {
                num = 0;
            }
            num++;
            int sanity = num;

            while (IsFactionTurnOver())
            {
                SetFactionActorsToNotMyTurn();
                if (num == length)
                {
                    num = 0;
                }
                num++;

                if (sanity == (int)ActiveFaction)
                {
                    EverybodysDeadDave();                     // uh
                }
                ActiveFaction = (EntityFaction)num;
                GiveFactionActorsATurn();
            }
        }
Exemple #2
0
 public Entity GetClosestCharacter(Vector2Int targetPosition, EntityFaction faction)
 {
     return(LevelData.Entities
            .Where(p => p.Type == EntityType.Character && p.Faction == faction)
            .OrderBy((entity) => Vector2Int.Distance(targetPosition, entity.GridPosition))
            .FirstOrDefault());
 }
Exemple #3
0
        public void Select(bool movementAllowed, bool attackAllowed)
        {
            this.possibleMoveTargets.Clear();
            this.possibleAttackTargets.Clear();

            if (movementAllowed)
            {
                gridNavigator.DoActionOnNeighbours(GridPosition, MaxWalkDistance, true,
                                                   (depth, gridPosition) =>
                {
                    possibleMoveTargets.Add(gridPosition);
                });
            }

            if (attackAllowed)
            {
                EntityFaction opposingFaction = Faction == EntityFaction.Player ? EntityFaction.Enemy : EntityFaction.Player;
                List <Entity> entitiesInRange = levelService.GetEntitiesInRange(this, opposingFaction);
                foreach (Entity entity in entitiesInRange)
                {
                    entity.SetTargeted(true);
                    possibleAttackTargets.Add(entity);
                }
            }
            OnSelected(this, true);
        }
Exemple #4
0
        public List <Entity> GetEntitiesInRange(Entity attacker, EntityFaction targetFaction)
        {
            int        range    = attacker.AttackRange;
            Vector2Int position = attacker.GridPosition;

            List <Entity> entitiesList = new List <Entity>();

            //Check x axis
            for (int xOffset = -range; xOffset <= range; xOffset++)
            {
                Vector2Int offsetPosition = new Vector2Int(position.x + xOffset, position.y);
                Entity     entity         = GetEntityAtPosition(offsetPosition.x, offsetPosition.y);
                if (entity != null && entity != attacker && entity.Faction == targetFaction)
                {
                    entitiesList.Add(entity);
                }
            }

            //Check y axis
            for (int yOffset = -range; yOffset <= range; yOffset++)
            {
                Vector2Int offsetPosition = new Vector2Int(position.x, position.y + yOffset);
                Entity     entity         = GetEntityAtPosition(offsetPosition.x, offsetPosition.y);
                if (entity != null && entity != attacker && entity.Faction == targetFaction)
                {
                    entitiesList.Add(entity);
                }
            }

            return(entitiesList);
        }
Exemple #5
0
 protected bool ArgumentIsFaction(string argument, out EntityFaction entityFaction)
 {
     entityFaction = (EntityFaction)Enum.Parse(typeof(EntityFaction), argument.ToUpper());
     if (!HostHandler.I.currentHost.GetPresentFactions().Contains(entityFaction))
     {
         return(false);
     }
     return(true);
 }
 private void Init(string targetId, EntityFaction targetFaction, Directory lastPosition, float weight, int ttl)
 {
     this.targetId      = targetId;
     this.targetFaction = targetFaction;
     this.lastPosition  = lastPosition;
     this.weight        = weight;
     this.ttl           = ttl;
     IOTerminal.I.onTerminalTimePast.AddListener(OnTerminalTimePast);
 }
 public EntityActor(string name, EntityFaction faction, int movementrange, int sightrange,
                    EntityCharacterMovementType movementtype)
 {
     _Name           = name;
     _Faction        = faction;
     _MovementPoints = movementrange;
     _SightRange     = sightrange;
     _MovementType   = movementtype;
     _Render         = new TilerIsADummy.PrototypeMapGen.PrototypeComponents.P_ActorRenderComponent(this);
 }
Exemple #8
0
 public void Init(Vector2Int gridPosition, GridNavigator gridNavigator, Sprite sprite, EntityType type, EntityFaction faction, LevelService levelService)
 {
     this.levelService  = levelService;
     this.gridNavigator = gridNavigator;
     GridPosition       = gridPosition;
     Type       = type;
     Faction    = faction;
     EntityView = GetComponent <EntityView>() ?? gameObject.AddComponent <EntityView>();
     EntityView.Init(this, sprite, type, gridPosition, levelService);
 }
Exemple #9
0
        private bool TryAttackFractionInRange(EntityFaction targetFaction)
        {
            List <Entity> entitiesInRange = levelService.GetEntitiesInRange(this, targetFaction);

            if (entitiesInRange.Count > 0)
            {
                Attack(entitiesInRange[0]);
                return(true);
            }
            return(false);
        }
    // Start is called before the first frame update
    void Start()
    {
        EntityFaction bandits = new EntityFaction("Bandits!");

        for (int i = 0; i < 5; i++)
        {
            Vector2 pos = GameManager.RNG.RandomVector2(15, 25);
            Bandit  b   = new Bandit();
            b.SetEntityFaction(bandits);
            b.MoveEntity(Vec2i.FromVector2(pos));
            EntityManager.Instance.LoadEntity(b);
        }
    }
    protected virtual void FindTargets()
    {
        EntityFaction myFaction = entityBody.faction;

        if (!GetEntitiesInScanRange(out List <Entity> entities))
        {
            return;
        }
        entities = entities.OrderBy(x => RandomUtil.random.Next()).ToList();
        foreach (Entity entity in entities)
        {
            ProcessNewTargetData(entity);
        }
    }
Exemple #12
0
        public Projectile(Vector2 pos, float rotation, float speed, int inTier, EntityFaction inFaction, int inDamage)
        {
            this.position = pos;

            float jitter = -jitterAmount + PlayField.GetRandom().Next((int)(jitterAmount * 2));
            this.rotation = rotation + jitter;

            this.damage = inDamage;
            this.speed = speed;
            this.maxSpeed = speed;
            this.tier = inTier;
            this.entityFaction = inFaction;

            GetTexture(tier);
            SetOrigin();
        }
    public override void Generate(GenerationRandom ran)
    {
        GenRan = ran;
        BuildWallAndEntrance();
        GenerateSubworldCave(new Vec2i(TileSize.x - 10, TileSize.z - 10));
        DEBUG = false;
        EntityFaction bandits = new EntityFaction("Bandits");

        for (int i = 0; i < 10; i++)
        {
            Vector3 pos    = GenRan.RandomVector3(Boundry + 2, Mathf.Min(TileSize.x, TileSize.z) - Boundry - 2);
            Bandit  bandit = new Bandit();
            bandit.SetEntityFaction(bandits);
            bandit.MoveEntity(pos);
            AddEntity(bandit);
        }
    }
Exemple #14
0
        public IPromise MakeAITurn()
        {
            EntityFaction opposingFaction = Faction == EntityFaction.Player ? EntityFaction.Enemy : EntityFaction.Player;
            bool          attackSuccess   = TryAttackFractionInRange(opposingFaction);

            if (attackSuccess == false)
            {
                Entity closestPlayerCharacter = levelService.GetClosestCharacter(GridPosition, opposingFaction);
                if (closestPlayerCharacter != null)
                {
                    List <Vector2Int> path        = gridNavigator.GetPath(this, closestPlayerCharacter.GridPosition, MaxWalkDistance, closestPlayerCharacter);
                    Vector2Int        moveTarget  = path.Last() == closestPlayerCharacter.GridPosition ? path[path.Count - 2] : path[path.Count - 1];
                    IPromise          movePromise = Move(moveTarget);
                    movePromise.Done(() => TryAttackFractionInRange(opposingFaction));
                    return(movePromise);
                }
            }
            return(Deferred.GetFromPool().Resolve());
        }
Exemple #15
0
        public P_BattleMap(List <TilerIsADummy.IEntity> entitylist, P_TileArray tilearray, IP_UpdateManager updater, P_Render renderer)
        {
            TheMap    = tilearray;
            MapEntity = entitylist;

            Updater  = updater;
            Renderer = renderer;
            _Render  = new PrototypeComponents.P_RenderComponent();

            this.AcceptP_Render(Renderer);
            this.AcceptUpdater(Updater);
            Active             = true;
            this.ActiveFaction = EntityFaction.Player;

            for (int i = 0; i < entitylist.Count; i++)
            {
                entitylist[i].MyMap = TheMap;
                entitylist[i].AcceptP_Render(renderer);
                entitylist[i].AcceptUpdater(updater);
            }

            foreach (EntityActor thing in entitylist)
            {
                thing.ActiveState = EntityCharacterState.Active;
            }

            for (int i = 0; i < tilearray.MyTiles.Length; i++)
            {
                tilearray.MyTiles[i].AcceptP_Render(renderer);
                tilearray.MyTiles[i].Render.OffsetBoss = this;
            }

            PlaceActorsOnMap(entitylist);
            GiveFactionActorsATurn();

            MyState = new P_BMSPlayerSelectingTile(this);
            //tilearray.AcceptUpdater(updater);
        }
    private Dungeon GenerateFireDungeon(DungeonEntrance entrance)
    {
        ChunkData[,] dungeonChunks = new ChunkData[5, 5];
        Dictionary <int, WorldObjectData>[,] chunkObjects = new Dictionary <int, WorldObjectData> [5, 5];


        for (int x = 0; x < 5; x++)
        {
            for (int z = 0; z < 5; z++)
            {
                chunkObjects[x, z] = new Dictionary <int, WorldObjectData>();


                dungeonChunks[x, z] = new ChunkData(x, z, (int[, ])BASE_DIRT.Clone(), true, chunkObjects[x, z]);
            }
        }
        Vec2i         chunkPos        = World.GetChunkPosition(entrance.WorldPosition);
        Vec2i         dungEntr        = new Vec2i(5, 5);
        EntityFaction dungFact        = new EntityFaction("Dungeon_faction");
        List <Entity> dungeonEntities = new List <Entity>();
        DungeonBoss   testBoss        = new DungeonBossTest(new BasicHumanoidCombatAI(), new CreatureTaskAI());

        testBoss.SetEntityFaction(dungFact);

        for (int i = 0; i < 25; i++)
        {
            Vec2i  randomPos = GenRan.RandomVec2i(World.ChunkSize, 5 * World.ChunkSize - 5);
            Entity newEnt    = new Bandit();
            newEnt.SetPosition(randomPos);
            newEnt.SetEntityFaction(dungFact);
            dungeonEntities.Add(newEnt);
        }
        Dungeon dungeon = new Dungeon(dungeonChunks, dungEntr, entrance.WorldPosition, dungeonEntities, testBoss);

        entrance.SetDungeon(dungeon);
        return(dungeon);
    }
    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());
    }
Exemple #18
0
 public void SetEntityFaction(EntityFaction entFact)
 {
     EntityFaction = entFact;
 }
Exemple #19
0
        private void InstantiateEntity(Vector2Int gridPosition, Sprite sprite, EntityType type, EntityFaction faction)
        {
            Entity newEntity = GameObject.Instantiate(entityPrefab, Vector3.zero, Quaternion.identity, entitiesContainer);

            newEntity.name = type.ToString();
            newEntity.Init(gridPosition, gridNavigator, sprite, type, faction, this);
            if (type == EntityType.Character)
            {
                string pathToConfig = "Configs/" + "DefaultCharacterConfig";
                var    config       = Resources.Load <CharacterConfig>(pathToConfig);
                newEntity.AddCharacterParams(config, stepDuration);
                newEntity.OnMovementFinished += OnEntityMoved;
                newEntity.OnDestroyed        += OnEntityDestroyed;
                newEntity.OnSelected         += OnEntitySelected;
                newEntity.OnAttack           += OnEntityAttack;
            }
            LevelData.Entities.Add(newEntity);
            LevelData.TilesEntities[gridPosition.x, gridPosition.y] = newEntity;
        }
 public TargetData(string targetId, EntityFaction targetFaction, Directory lastPosition, float weight, int ttl)
 {
     Init(targetId, targetFaction, lastPosition, weight, ttl);
 }