Ejemplo n.º 1
0
        public void Execute(int search, VehicleRequestDTO request)
        {
            var vehicle = AiContext.Vehicles
                          .Find(search);

            if (vehicle == null || vehicle.IsDeleted == 1)
            {
                throw new EntityNotFoundException("Vehicle");
            }
            var existingBrand = AiContext.Brands
                                .Find(request.BrandId);

            if (existingBrand == null)
            {
                throw new EntityNotFoundException("Brand");
            }
            var existingVehType = AiContext.VehicleTypes
                                  .Find(request.VehicleTypeId);

            if (existingVehType == null)
            {
                throw new EntityNotFoundException("Vehicle type");
            }
            vehicle.Automatic        = request.Automatic.HasValue ? request.Automatic.Value : false;
            vehicle.Model            = request.Model;
            vehicle.CostPerDay       = request.CostPerDay;
            vehicle.BrandId          = request.BrandId;
            vehicle.VehicleTypeId    = request.VehicleTypeId;
            vehicle.FuelTankCapacity = request.FuelTankCapacity;
            vehicle.Color            = request.Color;
            vehicle.ModifiedAt       = DateTime.Now;
            AiContext.SaveChanges();
        }
Ejemplo n.º 2
0
        public override UtilityPick EvaluateAbsoluteUtility(AiContext context)
        {
            if (evaluatedParamName != AiContextVariable.None)
            {
                var averageScores = GetSumScores(context);
                if (averageScores != null)
                {
                    var considerationsCount = (float)considerations.Count;
                    var maxIdx = -1;
                    var maxAvg = 0f;
                    for (var i = 0; i < averageScores.Length; i++)
                    {
                        var score = averageScores[i];
                        score /= considerationsCount;
                        if (score > maxAvg)
                        {
                            maxAvg = score;
                            maxIdx = i;
                        }
                    }

                    return(new UtilityPick(this, ActionWeight * maxAvg, maxIdx));
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
        protected override bool GetBranch(AiContext context)
        {
            var canMove = moveFinder.Find(Unit, context);

            Unit.NextMove = moveFinder.MoveInfo;
            return(canMove);
        }
Ejemplo n.º 4
0
        public List <float> Evaluate(AiContext context, int len = 1)
        {
            var pick = new List <float>();

            if (evaluatedContextVariable != AiContextVariable.None)
            {
                if (context.GetParameter(evaluatedContextVariable) is List <float> evaluatedParams)
                {
                    for (var i = 0; i < evaluatedParams.Count; i++)
                    {
                        pick.Add(EvaluateAt(evaluatedParams[i]));
                    }
                }
                else
                {
                    if (context.GetParameter(evaluatedContextVariable) is float evaluatedParam)
                    {
                        pick = new List <float>();
                        var score = EvaluateAt(evaluatedParam);
                        for (var i = 0; i < len; i++)
                        {
                            pick.Add(score);
                        }
                    }
                }
            }
            return(pick);
        }
Ejemplo n.º 5
0
        public void Execute(int request)
        {
            var rent = AiContext.Rents
                       .Find(request);

            if (rent == null || rent.IsDeleted == 1)
            {
                throw new EntityNotFoundException("Rent");
            }
            //Only rents in progress can be stopped
            if (rent.StatusId != 10)
            {
                throw new IndexOutOfRangeException();
            }
            var vehicle = AiContext.Vehicles
                          .Find(rent.VehicleId);

            vehicle.Rented     = false;
            vehicle.ModifiedAt = DateTime.Now;
            rent.StatusId      = 11;
            rent.ModifiedAt    = DateTime.Now;
            AiContext.SaveChanges();
            _emailSender.Body    = "Your rent has ended, thank you for using our service!";
            _emailSender.Subject = "Rent reservation";
            _emailSender.ToEmail = rent.Email;
            _emailSender.Send();
        }
Ejemplo n.º 6
0
        public override IDecisionTreeNode MakeDecision(AiContext context)
        {
            var decisionCommand = new WaitForAlliesToMoveCommand(Unit, context);

            context.InsertCommand(Zero, decisionCommand);
            return(this);
        }
        public void Execute(int search, ExtraAddonRequestDTO request)
        {
            var extra = AiContext.ExtraAddons
                        .Find(search);

            if (extra == null || extra.IsDeleted == 1)
            {
                throw new EntityNotFoundException("Extra Add-on");
            }
            var existingName = AiContext.ExtraAddons
                               .Where(x => x.Name == request.Name)
                               .Where(x => x.Id != extra.Id)
                               .Where(x => x.IsDeleted == 0)
                               .FirstOrDefault();

            if (existingName != null)
            {
                throw new EntityExistsException("Extra Add-on");
            }
            var extraUpdate = new ExtraAddon();

            extra.Name       = request.Name;
            extra.Price      = request.Price;
            extra.ModifiedAt = DateTime.Now;
            AiContext.SaveChanges();
        }
 public override void Execute(AiContext context, UtilityPick pick)
 {
     _lastInvokedTime = Time.time;
     _invokedTimes++;
     _inExecution = true;
     actionTask?.Invoke(context, pick);
 }
 public FinishMoveCommand(AiContext context, IUnit unit, Coord to, IEventBus bus)
 {
     this.context = context;
     this.unit    = unit;
     this.to      = to;
     this.bus     = bus;
 }
Ejemplo n.º 10
0
        public override IDecisionTreeNode MakeDecision(AiContext context)
        {
            var decisionCommand = new MakeDecisionCommand(Unit, context, MoveDiffTime);

            context.InsertCommand(MoveDiffTime, decisionCommand);

            Bus.Raise(new IdleEvent(Unit.Coord));
            return(this);
        }
Ejemplo n.º 11
0
        protected override bool GetBranch(AiContext context)
        {
            var target       = Unit.ArrivingTargets.MinBy(u => u.TimeWhenDecisionWillBeExecuted);
            var timeToArrive = target.TimeWhenDecisionWillBeExecuted - context.CurrentTime;

            Unit.ChangeTargetTo(target);

            return(timeToArrive < StraightMoveTime ? true : false);
        }
Ejemplo n.º 12
0
        public override IDecisionTreeNode MakeDecision(AiContext context)
        {
            var(coord, time) = Unit.NextMove;
            new StartMoveCommand(context, Unit, coord, time, Bus).Execute();

            context.InsertCommand(time, new FinishMoveCommand(context, Unit, coord, Bus));
            context.InsertCommand(time, new MakeDecisionCommand(Unit, context, time));
            return(this);
        }
        public override IDecisionTreeNode MakeDecision(AiContext context)
        {
            var time = Unit.Target.TimeWhenDecisionWillBeExecuted - context.CurrentTime;

            context.InsertCommand(time, new MakeDecisionCommand(Unit, context, time));

            Bus.Raise(new IdleEvent(Unit.Coord));
            return(this);
        }
Ejemplo n.º 14
0
        public void GoToTarget(AiContext context, UtilityPick pick)
        {
            var hitGameObject = context.target;
            var owner         = context.owner as NpcMainScript;

            if (owner != null)
            {
                owner._agent.SetDestination(hitGameObject.transform.position);
            }
        }
Ejemplo n.º 15
0
        public override IDecisionTreeNode MakeDecision(AiContext context)
        {
            context.InsertCommand(Zero, new ApplyDamageCommand(Unit, context, Bus)); //inserting to heap because units can attack at the same time
            context.InsertCommand(Unit.TimeToFinishAttackAnimation, new FinishAttackCommand(Unit, Bus));

            var time = Max(Unit.AttackSpeedTime, Unit.TimeToFinishAttackAnimation);

            context.InsertCommand(time, new MakeDecisionCommand(Unit, context, time));
            return(this);
        }
 public StartMoveCommand(AiContext context, IUnit unit, Coord newCoord,
                         F32 duration, IEventBus bus)
 {
     this.context  = context;
     startingTime  = context.CurrentTime;
     this.unit     = unit;
     this.newCoord = newCoord;
     this.duration = duration;
     this.bus      = bus;
 }
        public override UtilityPick Select(AiContext context, List <AbstractUtilityAction> actions)
        {
            var utilities = new List <UtilityWeights>();

            foreach (var action in actions)
            {
                UtilityPick utility = action.EvaluateAbsoluteUtility(context);
                if (utility != null && utility.Score > 0f)
                {
                    utilities.Add(new UtilityWeights(utility.Score, utility));
                }
            }

            var count = utilities.Count;

            if (count > 0)
            {
                utilities.Sort((first, second) => first.Rank.CompareTo(second.Rank));

                var std = utilities.GetStd();
                var sum = 0f;

                var minWeight = float.PositiveInfinity;
                var maxWeight = 0f;

                var selected = new List <UtilityWeights>();
                foreach (var u in utilities)
                {
                    if (u.Rank < std)
                    {
                        continue;
                    }
                    selected.Add(u);
                    sum += u.Rank;
                }

                foreach (var u in selected)
                {
                    u.Weight = u.Rank / sum;
                    if (u.Weight > maxWeight)
                    {
                        maxWeight = u.Weight;
                    }
                    if (u.Weight < minWeight)
                    {
                        minWeight = u.Weight;
                    }
                }
                // TODO: Weights are equal to 1 on the first run ??
                var rand = Random.Range(minWeight, maxWeight);
                return(utilities.Find(u => u.Weight >= rand).UAction);
            }

            return(null);
        }
        public override IDecisionTreeNode MakeDecision(AiContext context)
        {
            var units = context.EnemyUnits(Unit.Player);
            //TODO: check if it's moving and if so record that in unit
            var target = Unit.FindNearestTarget(units);

            Unit.ChangeTargetTo(target);

            context.InsertCommand(Zero, new MakeDecisionCommand(Unit, context, Zero));
            return(this);
        }
        public void Execute(int request)
        {
            var extra = AiContext.ExtraAddons.Find(request);

            if (extra == null || extra.IsDeleted == 1)
            {
                throw new EntityNotFoundException("Extra Add-on");
            }
            extra.IsDeleted = 1;
            AiContext.SaveChanges();
        }
        public void Execute(int request)
        {
            var brand = AiContext.Brands.Find(request);

            if (brand == null || brand.IsDeleted == 1)
            {
                throw new EntityNotFoundException("Brand");
            }
            brand.IsDeleted = 1;
            AiContext.SaveChanges();
        }
        public override IDecisionTreeNode MakeDecision(AiContext context)
        {
            Unit.StartAttack(context.CurrentTime);

            context.InsertCommand(Unit.AttackAnimationHitTime,
                                  new MakeDecisionCommand(Unit, context, Unit.AttackAnimationHitTime));

            Bus.Raise(new RotateEvent(Unit.Coord, Unit.Target.Coord));
            Bus.Raise(new StartAttackEvent(Unit.Coord));
            return(this);
        }
        public void Execute(int request)
        {
            var user = AiContext.Users.Find(request);

            if (user == null || user.IsDeleted == 1)
            {
                throw new EntityNotFoundException("User");
            }
            user.IsDeleted = 1;
            AiContext.SaveChanges();
        }
        public void Execute(int request)
        {
            var vehType = AiContext.VehicleTypes
                          .Find(request);

            if (vehType == null || vehType.IsDeleted == 1)
            {
                throw new EntityNotFoundException("Vehicle type");
            }
            vehType.IsDeleted = 1;
            AiContext.SaveChanges();
        }
Ejemplo n.º 24
0
 public void GoToCover(AiContext context, UtilityPick pick)
 {
     if (pick.UtilityAction is PickerAction picker)
     {
         var choices = context.GetParameter(picker.evaluatedParamName) as List <Vector3>;
         var owner   = context.owner as NpcMainScript;
         if (pick.SelectorIdx != -1)
         {
             owner._agent.SetDestination(choices[pick.SelectorIdx]);
         }
     }
 }
        public void Execute(int request)
        {
            var location = AiContext.Locations
                           .Find(request);

            if (location == null || location.IsDeleted == 1)
            {
                throw new EntityNotFoundException("Location");
            }
            location.IsDeleted = 1;
            AiContext.SaveChanges();
        }
Ejemplo n.º 26
0
        public void Execute(int request, UserUpdatePasswordRequest pass)
        {
            var user = AiContext.Users.Find(request);

            if (user == null || user.IsDeleted == 1)
            {
                throw new EntityNotFoundException("User");
            }
            user.Password   = pass.Password;
            user.ModifiedAt = DateTime.Now;
            AiContext.SaveChanges();
        }
Ejemplo n.º 27
0
 public BattleSimulationDebugController(BattleSimulation simulation, BattleSimulationUI ui,
                                        AiContext context, PlayerContext playerContext,
                                        PlayerPresenterContext playerPresenterContext,
                                        RealtimeBattleSimulationController realtimeBattleSimulationController,
                                        BattleSimulationPresenter simulationPresenter)
 {
     this.simulation                         = simulation;
     this.ui                                 = ui;
     this.context                            = context;
     this.playerContext                      = playerContext;
     this.playerPresenterContext             = playerPresenterContext;
     this.realtimeBattleSimulationController = realtimeBattleSimulationController;
     this.simulationPresenter                = simulationPresenter;
 }
        public void Execute(int search, CustomerRequestDTO request)
        {
            var customer = AiContext.Customers.Find(search);

            if (customer == null || customer.IsDeleted == 1)
            {
                throw new EntityNotFoundException("Customer");
            }
            customer.FirstName   = request.FirstName;
            customer.LastName    = request.LastName;
            customer.Email       = request.Email;
            customer.PhoneNumber = request.PhoneNumber;
            customer.Birthday    = request.Birthday;
            customer.ModifiedAt  = DateTime.Now;
            AiContext.SaveChanges();
        }
        public override float Qualify(AiContext context, List <ContextConsideration> considerations)
        {
            var product = 1f;

            foreach (var consideration in considerations)
            {
                if (consideration.isEnabled)
                {
                    product *= consideration.Evaluate(context);
                }
            }
            var modificationFactor = 1f - 1f / considerations.Count;
            var makeUpValue        = (1f - product) * modificationFactor;

            return(product + makeUpValue * product);
        }
Ejemplo n.º 30
0
        public void Execute(int request)
        {
            var role = AiContext.Roles.Find(request);

            if (role == null || role.IsDeleted == 1)
            {
                throw new EntityNotFoundException("Role");
            }
            role.IsDeleted  = 1;
            role.ModifiedAt = DateTime.UtcNow;
            var users = AiContext.Users
                        .Where(u => u.RoleId == request);

            foreach (var user in users)
            {
                user.RoleId = 8;
            }
            AiContext.SaveChanges();
        }