protected override GoalEntity CreateGoalEx(int goalKind)
        {
            GoalEntity result = null;

            switch (goalKind)
            {
            case GoalKind.gk_Travel:
                result = new TravelGoal(this);
                break;

            case GoalKind.gk_PointGuard:
                result = new PointGuardGoal(this);
                break;

            case GoalKind.gk_ItemAcquire:
                result = new ItemAcquireGoal(this);
                break;

            case GoalKind.gk_EnemyChase:
                result = new EnemyChaseGoal(this);
                break;

            case GoalKind.gk_EnemyEvade:
                result = new EnemyEvadeGoal(this);
                break;

            case GoalKind.gk_AreaGuard:
                result = new AreaGuardGoal(this);
                break;

            case GoalKind.gk_ShopReturn:
                result = new ShopReturnGoal(this);
                break;

            case GoalKind.gk_PlayerFind:
                result = new PlayerFindGoal(this);
                break;

            case GoalKind.gk_Escort:
                result = new EscortGoal(this);
                break;

            case GoalKind.gk_Flock:
                result = new FlockGoal(this);
                break;

            case GoalKind.gk_DebtTake:
                result = new DebtTakeGoal(this);
                break;

            case GoalKind.gk_WareReturn:
                result = new WareReturnGoal(this);
                break;

            case GoalKind.gk_Stalk:
                result = new StalkGoal(this);
                break;
            }
            return(result);
        }
        protected override void EvaluateGoal(GoalEntity goal)
        {
            switch (goal.Kind)
            {
            case GoalKind.gk_Unknown:
                goal.Value = 0f;
                break;

            case GoalKind.gk_Travel:
                goal.Value = 0.225f;
                break;

            case GoalKind.gk_PointGuard:
            {
                int dist = MathHelper.Distance(fSelf.Location, ((PointGuardGoal)goal).Position);
                goal.Value = (0.2f + dist / 10.0f);
                break;
            }

            case GoalKind.gk_EnemyChase:
                goal.Value = 0.6f;
                break;

            case GoalKind.gk_EnemyEvade:
                goal.Value = 0.75f;
                if (Flock && !IsLeader)
                {
                    goal.Value = ((0.75f - 0.1f * Kinsfolks.Count));
                }
                break;

            case GoalKind.gk_Friend:
                goal.Value = 0.27f;
                break;

            case GoalKind.gk_AreaGuard:
                goal.Value = 0.2f;
                break;

            case GoalKind.gk_Escort:
            {
                int dist = MathHelper.Distance(fSelf.Location, ((EscortGoal)goal).Position);
                goal.Value = ((0.3f + dist / 20.0f));
                break;
            }

            case GoalKind.gk_Flock:
                goal.Value = 0.22f;
                if (Flock && !IsLeader)
                {
                    goal.Value = ((0.22f + 0.01f * Kinsfolks.Count));
                }
                break;

            case GoalKind.gk_Stalk:
                goal.Value = 0.55f;
                break;
            }
        }
        public void DependOnGoal()
        {
            GoalEntity other = Factory.GetGoalEntity();

            bool result = TestObject.AddDependency(other);

            Assert.IsFalse(result, "Should not be able to depend on Goal entities.");
        }
Beispiel #4
0
        public void DependOnAnotherGoal()
        {
            GoalEntity other = Factory.GetGoalEntity();

            bool result = TestObject.AddDependency(other);

            Assert.IsTrue(result, "Should be able to depend on other Goals.");
        }
Beispiel #5
0
 // PUT: api/Goal/5
 public bool Put(int id, [FromBody] GoalEntity GoalEntity)
 {
     if (id > 0)
     {
         return(_GoalServices.UpdateGoal(id, GoalEntity));
     }
     return(false);
 }
Beispiel #6
0
        protected override void EvaluateGoal(GoalEntity goal)
        {
            switch (goal.Kind)
            {
            case GoalKind.gk_PlayerFind:
                goal.Value = 0.8f;
                break;

            default:
                base.EvaluateGoal(goal);
                break;
            }
        }
Beispiel #7
0
        protected override void EvaluateGoal(GoalEntity goal)
        {
            switch (goal.Kind)
            {
            case GoalKind.gk_ItemAcquire:
                goal.Value = 0.25f;
                break;

            default:
                base.EvaluateGoal(goal);
                break;
            }
        }
Beispiel #8
0
 public static GoalModel ToModel(this GoalEntity entity)
 {
     if (entity == null)
     {
         return(null);
     }
     return(new GoalModel
     {
         Id = entity.Id,
         Title = entity.Title,
         Description = entity.Description,
         Importance = entity.Importance
     });
 }
Beispiel #9
0
 public int CreateGoal(GoalEntity goalEntity)
 {
     using (var scope = new TransactionScope())
     {
         var goal = new Goal()
         {
             goalId      = goalEntity.goalId,
             name        = goalEntity.name,
             description = goalEntity.description
         };
         _unitOfWork.GoalRepository.Insert(goal);
         _unitOfWork.Save();
         scope.Complete();
         return(goal.goalId);
     }
 }
Beispiel #10
0
        protected override void EvaluateGoal(GoalEntity goal)
        {
            try {
                NWCreature self = (NWCreature)fSelf;
                int        gk   = goal.Kind;

                switch (gk)
                {
                case GoalKind.gk_ShopReturn:
                    goal.Value = 0.23f;
                    break;

                case GoalKind.gk_DebtTake:
                {
                    DebtTakeGoal dtGoal = (DebtTakeGoal)goal;
                    if (self.IsAvailable(dtGoal.Debtor, true))
                    {
                        goal.Value = 1f;
                    }
                    else
                    {
                        goal.Value = 0.1f;
                    }
                }
                break;

                case GoalKind.gk_WareReturn:
                    Building house = (Building)self.FindHouse();
                    if (house.Area.Contains(self.PosX, self.PosY))
                    {
                        goal.Value = 0.9f;
                    }
                    else
                    {
                        goal.Value = 0.22f;
                    }
                    break;

                default:
                    base.EvaluateGoal(goal);
                    break;
                }
            } catch (Exception ex) {
                Logger.Write("TraderBrain.evaluateGoal(): " + ex.Message);
            }
        }
Beispiel #11
0
        public bool UpdateGoal(int goalId, GoalEntity goalEntity)
        {
            var success = false;

            if (goalEntity != null)
            {
                using (var scope = new TransactionScope())
                {
                    var goal = _unitOfWork.GoalRepository.GetByID(goalId);
                    if (goal != null)
                    {
                        goal.goalId      = goalEntity.goalId;
                        goal.name        = goalEntity.name;
                        goal.description = goalEntity.description;
                        _unitOfWork.Save();
                        scope.Complete();
                        success = true;
                    }
                }
            }
            return(success);
        }
        private void PrepareFlock()
        {
            try {
                IsLeader = true;
                Kinsfolks.Clear();

                NWCreature self = (NWCreature)fSelf;
                NWField    fld  = self.CurrentField;

                fNearKinsfolk     = null;
                fNearKinsfolkDist = AuxUtils.MaxInt;

                int num = fld.Creatures.Count;
                for (int i = 0; i < num; i++)
                {
                    NWCreature cr   = fld.Creatures.GetItem(i);
                    int        dist = MathHelper.Distance(cr.Location, self.Location);
                    if (!cr.Equals(self) && dist <= self.Survey && cr.CLSID == self.CLSID && fld.LineOfSight(self.PosX, self.PosY, cr.PosX, cr.PosY))
                    {
                        Kinsfolks.Add(cr);
                        if (fNearKinsfolkDist > dist)
                        {
                            fNearKinsfolkDist = dist;
                            fNearKinsfolk     = cr;
                        }
                        IsLeader = (IsLeader && self.Leadership > cr.Leadership);
                    }
                }

                if (FindGoalByKind(GoalKind.gk_Flock) == null)
                {
                    GoalEntity goal = CreateGoal(GoalKind.gk_Flock);
                    goal.Duration = 25;
                }
            } catch (Exception ex) {
                Logger.Write("BeastBrain.prepareFlock(): " + ex.Message);
            }
        }
Beispiel #13
0
        protected override void EvaluateGoal(GoalEntity goal)
        {
            if (IsShipSail && (goal.Kind != GoalKind.gk_EnemyChase && goal.Kind != GoalKind.gk_EnemyEvade))
            {
                goal.Value = -1.0f;
                return;
            }

            NWCreature self = (NWCreature)fSelf;

            if (self.Mercenary)
            {
                switch (goal.Kind)
                {
                case GoalKind.gk_ItemAcquire:
                    goal.Value = 0.5f;
                    break;

                case GoalKind.gk_EnemyChase:
                    goal.Value = 0.6f;
                    break;

                case GoalKind.gk_EnemyEvade:
                    goal.Value = 0.25f;
                    break;

                case GoalKind.gk_Escort:
                {
                    int dist = MathHelper.Distance(self.Location, ((EscortGoal)goal).Position);
                    goal.Value = ((0.3f + dist / 20.0f));
                    break;
                }

                default:
                    base.EvaluateGoal(goal);
                    break;
                }
            }
            else
            {
                switch (goal.Kind)
                {
                case GoalKind.gk_Travel:
                {
                    // ekGuardAlarm
                    if (goal.EmitterID != 0)
                    {
                        goal.Value = 0.55f;
                    }
                    break;
                }

                case GoalKind.gk_PointGuard:
                {
                    int dist = MathHelper.Distance(self.Location, ((PointGuardGoal)goal).Position);
                    goal.Value = (goal.Value + dist / 10.0f * 0.75f);
                    break;
                }

                case GoalKind.gk_AreaGuard:
                {
                    int dist = AuxUtils.CalcDistanceToArea(self.Location, ((AreaGuardGoal)goal).Area);
                    goal.Value = ((goal.Value + dist / 100.0f));
                    break;
                }

                default:
                    base.EvaluateGoal(goal);
                    break;
                }
            }
        }
Beispiel #14
0
        void CreateEntities()
        {
            EdgeEntity.Create(_engine, Content.Load <Texture2D>(Constants.Resources.TEXTURE_PONG_EDGE),
                              new Vector2(0, Constants.Pong.PLAYFIELD_HEIGHT / 2),
                              new Vector2(0, -1)); // Top edge points down
            EdgeEntity.Create(_engine, Content.Load <Texture2D>(Constants.Resources.TEXTURE_PONG_EDGE),
                              new Vector2(0, -Constants.Pong.PLAYFIELD_HEIGHT / 2),
                              new Vector2(0, 1)); // Bottom edge points up

            // Field background
            FieldBackgroundEntity.Create(_engine, Content.Load <Texture2D>(Constants.Resources.TEXTURE_PONG_FIELD_BACKGROUND));

            // Player 1 goal
            GoalEntity.Create(_engine, _player1, Content.Load <Texture2D>(Constants.Resources.TEXTURE_PONG_GOAL),
                              new Vector2(-Constants.Pong.PLAYFIELD_WIDTH / 2 + Constants.Pong.GOAL_WIDTH / 2, 0));
            // Player 2 goal
            GoalEntity.Create(_engine, _player2, Content.Load <Texture2D>(Constants.Resources.TEXTURE_PONG_GOAL),
                              new Vector2(Constants.Pong.PLAYFIELD_WIDTH / 2 - Constants.Pong.GOAL_WIDTH / 2, 0));

            Entity paddle1 = PaddleEntity.Create(_engine,
                                                 Content.Load <Texture2D>(Constants.Resources.TEXTURE_PONG_PADDLE),
                                                 new Vector2(-Constants.Pong.PADDLE_STARTING_X,
                                                             Constants.Pong.PADDLE_STARTING_Y),
                                                 new Vector2(1, 0)); // Left paddle normal points right
            Entity paddle2 = PaddleEntity.Create(_engine,
                                                 Content.Load <Texture2D>(Constants.Resources.TEXTURE_PONG_PADDLE),
                                                 new Vector2(Constants.Pong.PADDLE_STARTING_X,
                                                             Constants.Pong.PADDLE_STARTING_Y),
                                                 new Vector2(-1, 0)); // Right paddle normal points left

            paddle1.AddComponent(new PlayerComponent(_player1));
            paddle2.AddComponent(new PlayerComponent(_player2));

            if (Player1 is AIPlayer)
            {
                paddle1.AddComponent(new AIComponent(Player1 as AIPlayer));
            }
            if (Player2 is AIPlayer)
            {
                paddle2.AddComponent(new AIComponent(Player2 as AIPlayer));
            }

            // Lives
            LivesEntity.Create(_engine,
                               Content.Load <BitmapFont>(Constants.Resources.FONT_PONG_LIVES),
                               new Vector2(Constants.Pong.LIVES_LEFT_POSITION_X, Constants.Pong.LIVES_POSITION_Y),
                               _player1,
                               Constants.Pong.LIVES_COUNT);
            BallEntity.CreateWithoutBehavior(_engine,
                                             Content.Load <Texture2D>(Constants.Resources.TEXTURE_PONG_BALL),
                                             new Vector2(Constants.Pong.LIVES_ICON_LEFT_POSITION_X,
                                                         Constants.Pong.LIVES_POSITION_Y),
                                             2);
            LivesEntity.Create(_engine,
                               Content.Load <BitmapFont>(Constants.Resources.FONT_PONG_LIVES),
                               new Vector2(Constants.Pong.LIVES_RIGHT_POSITION_X, Constants.Pong.LIVES_POSITION_Y),
                               _player2,
                               Constants.Pong.LIVES_COUNT);
            BallEntity.CreateWithoutBehavior(_engine,
                                             Content.Load <Texture2D>(Constants.Resources.TEXTURE_PONG_BALL),
                                             new Vector2(Constants.Pong.LIVES_ICON_RIGHT_POSITION_X,
                                                         Constants.Pong.LIVES_POSITION_Y),
                                             2);
        }
Beispiel #15
0
 public void Initialise()
 {
     TestObject = Factory.GetGoalEntity();
     Assert.IsNotNull(TestObject, "Failed to instantiate TestObject.");
 }
Beispiel #16
0
 // POST: api/Goal
 public int Post([FromBody] GoalEntity GoalEntity)
 {
     return(_GoalServices.CreateGoal(GoalEntity));
 }