Inheritance: ActorMission
コード例 #1
0
        /// <summary>
        /// Generates enemies on the map.
        /// </summary>
        /// <param name="enemyCount"></param>
        /// <param name="enemyType"></param>
        /// <returns></returns>
        public MapBlock[,] GenerateEnemies(MapBlock[,] blocks, int enemyCount, string enemyType, out DRObjects.Actor[] actors, int level, int equipmentCost = 0)
        {
            ItemFactory.ItemFactory fact = new ItemFactory.ItemFactory();
            List<Actor> actorList = new List<Actor>();

            //We'll just pick blocks at random until we fail 50 times in a row or run out of enemies to place
            int failureCount = 0;

            for (int i = 0; i < enemyCount; i++)
            {
                if (failureCount == 50)
                {
                    break;
                }

                int x = random.Next(blocks.GetLength(0));
                int y = random.Next(blocks.GetLength(1));

                //Is the block free
                if (blocks[x, y].MayContainItems)
                {
                    int returnedID = -1;
                    //Put the enemy in there

                    //Get the basic Actor object

                    double multiplier = GameState.Random.Next(75, 125);

                    multiplier /= 100; //So we get a number between 0.75 and 1.25

                    Actor actor = ActorGeneration.CreateActor(enemyType, null, null, (int)(level * multiplier), (int)(equipmentCost * multiplier), null, out returnedID);

                    var mapObject = fact.CreateItem("enemies", returnedID);

                    (mapObject as LocalCharacter).Actor = actor;

                    //Create the Actor
                    actor.GlobalCoordinates = null; //useless for now
                    actor.IsPlayerCharacter = false;
                    actor.MapCharacter = mapObject;

                    actorList.Add(actor);

                    blocks[x, y].ForcePutItemOnBlock(mapObject);

                    int missionType = random.Next(3);

                    if (missionType == 0)
                    {
                        //33% of them will Wander -
                        WanderMission mission = new WanderMission();
                        mission.WanderPoint = new MapCoordinate(x, y, 0, MapType.LOCAL);
                        mission.WanderRectangle = new Rectangle(0, 0, blocks.GetLength(0), blocks.GetLength(1));

                        actor.MissionStack.Push(mission);
                    }
                    else if (missionType == 1)
                    {
                        //33% will idle
                        IdleMission mission = new IdleMission();
                        actor.MissionStack.Push(mission);
                    }
                    else
                    {
                        //The rest will patrol
                        PatrolMission mission = new PatrolMission();
                        //Don't give them the point. We;ll choose it later
                        actor.MissionStack.Push(mission);
                    }

                    failureCount = 0;//reset
                }
                else
                {
                    failureCount++;
                    i--; //And again
                }
            }

            //return the map
            actors = actorList.ToArray();
            return blocks;
        }
コード例 #2
0
        public static ActionFeedback[] WanderMission(WanderMission mission, Actor actor)
        {
            MapCoordinate playerLocation = GameState.PlayerCharacter.MapCharacter.Coordinate;

            if (actor.UsesRanged)
            {
                //Is he a ranged user and seeing the player character
                if (actor.IsAggressive && actor.MapCharacter.Coordinate - playerLocation <= actor.LineOfSight)
                {
                    //Attack!
                    actor.MissionStack.Push(actor.CurrentMission);

                    actor.CurrentMission = new AttackMission(GameState.PlayerCharacter);
                }

            }
            else
            {
                //Is he seeing the player character?
                if (actor.IsAggressive && Math.Abs(actor.MapCharacter.Coordinate - playerLocation) <= 1)
                {
                    //He's there. Push the current mission into the stack and go on the attack
                    actor.MissionStack.Push(actor.CurrentMission);
                    actor.CurrentMission = new AttackMission(GameState.PlayerCharacter);
                    return new ActionFeedback[] { };
                }
                else if (actor.IsAggressive && Math.Abs(actor.MapCharacter.Coordinate - playerLocation) < actor.LineOfSight)
                {
                    //He's there. Push the current mission into the stack and follow him
                    actor.MissionStack.Push(actor.CurrentMission);
                    actor.CurrentMission = new HuntDownMission()
                    {
                        Target = GameState.PlayerCharacter,
                        TargetCoordinate = GameState.PlayerCharacter.MapCharacter.Coordinate
                    };

                    return new ActionFeedback[] { };
                }
            }

            //Perform an action accordingly
            //Is he outside of the patrol area?
            if (!mission.WanderRectangle.Contains(actor.MapCharacter.Coordinate.X, actor.MapCharacter.Coordinate.Y))
            {
                //Send him back.
                WalkToMission walkMission = new WalkToMission();
                walkMission.TargetCoordinate = mission.WanderPoint;

                //Push it
                actor.MissionStack.Push(mission);
                actor.CurrentMission = walkMission;
            }
            else
            {
                int randomNumber = GameState.Random.Next(100);
                //Do we wander?
                if (mission.LoiterPercentage != 0 && randomNumber < mission.LoiterPercentage)
                {
                    //Nope, we loiter
                }
                else
                {
                    //Walk somewhere randomly
                    int direction = GameState.Random.Next(4);

                    MapCoordinate coord = actor.MapCharacter.Coordinate;
                    //Copy it
                    MapCoordinate newCoord = new MapCoordinate(coord.X, coord.Y, coord.Z, coord.MapType);

                    switch (direction)
                    {
                        case 0: //Top
                            newCoord.Y++;
                            break;
                        case 1: //Bottom
                            newCoord.Y--;
                            break;
                        case 2: //Right
                            newCoord.X++;
                            break;
                        case 3: //Left
                            newCoord.X--;
                            break;
                    }

                    //Can we go there?
                    if (GameState.LocalMap.GetBlockAtCoordinate(newCoord).MayContainItems && mission.WanderRectangle.Contains(newCoord.X, newCoord.Y))
                    {
                        //Do it
                        GameState.LocalMap.GetBlockAtCoordinate(newCoord).PutItemOnBlock(actor.MapCharacter);
                        actor.MapCharacter.Coordinate = newCoord;

                        //And that's done
                    }
                }
                //Otherwise do nothing. Stay there
            }

            return new ActionFeedback[] { };
        }