コード例 #1
0
ファイル: HookUnit.cs プロジェクト: FoKycHuK/CVARC
        public UnitResponse ProcessCommand(object _command)
        {
            if (actor.IsDisabled)
            {
                return(UnitResponse.Denied());
            }

            if (hook.IsThrown)
            {
                hook.Pudge.ActivateBuff(PudgeEvent.HookThrown, hook.Pudge.Rules.HookThrown);
                return(UnitResponse.Accepted(0.1));
            }

            var command = Compatibility.Check <IHookCommand>(this, _command);

            if (command.MakeHook && !hook.Pudge.IsBuffActivated(PudgeEvent.HookCooldown))
            {
                if (hook.IsAvailable && actor.World.Configuration.LoadingData.Level != "Level1")
                {
                    Hook();
                }

                return(UnitResponse.Accepted(0.1));
            }

            return(UnitResponse.Denied());
        }
コード例 #2
0
        public UnitResponse ProcessCommand(object command)
        {
            var order = Compatibility.Check <IArmyInterfaceCommand>(this, command).HireOrder;

            if (order == null)
            {
                return(UnitResponse.Denied());
            }

            if (actor.IsDead)
            {
                return(UnitResponse.Accepted(HommRules.Current.UnitsHireDuration));
            }

            actor.World.HommEngine.Freeze(actor.ControllerId);
            actor.World.HommEngine.SetAnimation(actor.ControllerId, Animation.Idle);

            order.Apply(actor.Player);

            Debugger.Log($"{actor.ControllerId} resources:");

            foreach (var kv in actor.Player.Resources)
            {
                Debugger.Log($"{kv.Key} - {kv.Value}");
            }

            Debugger.Log($"{actor.ControllerId} army:");

            foreach (var kv in actor.Player.Army)
            {
                Debugger.Log($"{kv.Key} - {kv.Value}");
            }

            return(UnitResponse.Accepted(HommRules.Current.UnitsHireDuration));
        }
コード例 #3
0
        public UnitResponse ProcessCommand(object command)
        {
            var scoutOrder = Compatibility.Check <IScoutCommand>(this, command).ScoutOrder;

            if (scoutOrder == null)
            {
                return(UnitResponse.Denied());
            }

            if (!scoutOrder.ScoutHero ^ scoutOrder.ScoutTile)
            {
                throw new ArgumentException("Please scout either hero or tile at one time.");
            }

            if (scoutOrder.ScoutTile && !scoutOrder.TileToScout.ToLocation().IsInside(actor.Map.Size))
            {
                throw new ArgumentException("Tile to scout is out of map bounds.");
            }

            if (!actor.Player.Scout.IsAvailable())
            {
                throw new InvalidOperationException("Scouting is not available at a time. " +
                                                    "Please wait `HommRules.ScoutingCooldown` before sending a new scout.");
            }

            return(UnitResponse.Accepted(actor.Player.Scout.Execute(scoutOrder)));
        }
コード例 #4
0
        public List <PudgeRobot> GetEnemiesInScope()
        {
            Debugger.Log("Slardar " + slardar.ControllerId + " is searching for enemies");
            var engine          = slardar.World.GetEngine <ICommonEngine>();
            var slardarLocation = engine.GetAbsoluteLocation(slardar.ObjectId);
            var actors          = slardar.World.Actors
                                  .Where(a => a is PudgeRobot)
                                  .Select(a => Compatibility.Check <PudgeRobot>(this, a))
                                  .ToList();
            var result = new List <PudgeRobot>();

            foreach (var e in actors)
            {
                Debugger.Log("Considering " + e.ObjectId);
                if (e.ObjectId == slardar.ObjectId)
                {
                    Debugger.Log("is Slardar");
                }
                else if (e.IsDisabled)
                {
                    Debugger.Log("is Disabled");
                }
                else if (e.IsInvisible)
                {
                    Debugger.Log("is Invosible");
                }
                else
                {
                    var pudgeLocation = e.World.GetEngine <ICommonEngine>().GetAbsoluteLocation(e.ObjectId);
                    var distance      = Geometry.Distance(pudgeLocation.ToPoint3D(), slardarLocation.ToPoint3D());
                    var angle         = GetAngleToTarget(slardarLocation, pudgeLocation);
                    Debugger.Log("Target in at distance " + distance + " in angle " + angle);
                    if (angle < 45)
                    {
                        if (distance < slardar.Rules.ForwardVisibilityRadius)
                        {
                            Debugger.Log("Is inside forward visibility " + slardar.Rules.ForwardVisibilityRadius);
                            result.Add(e);
                        }
                        else
                        {
                            Debugger.Log("Is outside forward visibility " + slardar.Rules.ForwardVisibilityRadius);
                        }
                    }
                    else
                    {
                        if (distance < slardar.Rules.SideVisibilityRadius)
                        {
                            Debugger.Log("Is inside side  visibility " + slardar.Rules.SideVisibilityRadius);
                            result.Add(e);
                        }
                        else
                        {
                            Debugger.Log("Is outside side visibility " + slardar.Rules.SideVisibilityRadius);
                        }
                    }
                }
            }
            return(result);
        }
コード例 #5
0
ファイル: Hook.cs プロジェクト: FoKycHuK/CVARC
 public Hook(IHookRobot pudge, IHookRules rules)
 {
     Pudge            = Compatibility.Check <PudgeRobot>(this, pudge);
     Speed            = new Frame3D();
     StartingLocation = new Frame3D();
     Id    = Pudge.World.IdGenerator.CreateNewId(this);
     Rules = rules;
 }
コード例 #6
0
 public SlardarBot(List <Frame3D> trajectory, IActor slardar, string slardarType)
 {
     this.slardar        = Compatibility.Check <Slardar>(this, slardar);
     PathFinder          = new PathFinder(trajectory, slardarType);
     Trajectory          = trajectory;
     Type                = slardarType;
     this.slardar.OnDie += OnDie;
 }
コード例 #7
0
ファイル: HommRules.cs プロジェクト: niemandkun/homm
        public void DefineKeyboardControl(IKeyboardController _pool, string controllerId)
        {
            var pool = Compatibility.Check <KeyboardController <HommCommand> >(this, _pool);

            if (controllerId == TwoPlayersId.Left)
            {
                pool.Add(Keys.W, () => new HommCommand {
                    Movement = new Movement(Direction.Up)
                });
                pool.Add(Keys.S, () => new HommCommand {
                    Movement = new Movement(Direction.Down)
                });
                pool.Add(Keys.A, () => new HommCommand {
                    Movement = new Movement(Direction.LeftDown)
                });
                pool.Add(Keys.D, () => new HommCommand {
                    Movement = new Movement(Direction.RightDown)
                });
                pool.Add(Keys.Q, () => new HommCommand {
                    Movement = new Movement(Direction.LeftUp)
                });
                pool.Add(Keys.E, () => new HommCommand {
                    Movement = new Movement(Direction.RightUp)
                });
                pool.Add(Keys.Space, () => new HommCommand {
                    Order = new PurchaseOrder(10)
                });
            }
            else if (controllerId == TwoPlayersId.Right)
            {
                pool.Add(Keys.I, () => new HommCommand {
                    Movement = new Movement(Direction.Up)
                });
                pool.Add(Keys.K, () => new HommCommand {
                    Movement = new Movement(Direction.Down)
                });
                pool.Add(Keys.J, () => new HommCommand {
                    Movement = new Movement(Direction.LeftDown)
                });
                pool.Add(Keys.L, () => new HommCommand {
                    Movement = new Movement(Direction.RightDown)
                });
                pool.Add(Keys.U, () => new HommCommand {
                    Movement = new Movement(Direction.LeftUp)
                });
                pool.Add(Keys.O, () => new HommCommand {
                    Movement = new Movement(Direction.RightUp)
                });
                pool.Add(Keys.Enter, () => new HommCommand {
                    Order = new PurchaseOrder(10)
                });
            }

            pool.StopCommand = () => new HommCommand {
                Movement = new Wait()
            };
        }
コード例 #8
0
ファイル: ArmyInterfaceUnit.cs プロジェクト: niemandkun/homm
        public UnitResponse ProcessCommand(object command)
        {
            var order = Compatibility.Check <IArmyInterfaceCommand>(this, command).Order;

            if (order == null)
            {
                return(UnitResponse.Denied());
            }

            order.Apply(actor.Player);

            return(UnitResponse.Accepted(HommRules.Current.BuyDuration));
        }
コード例 #9
0
 private List <HeroData> GetVisibleHeroes(Point3D actorLocation)
 {
     return(Actor.World.Actors
            .Where(a => a.ObjectId != Actor.ObjectId && !a.IsDisabled)
            .Where(a => !(a is PudgeRobot) || !Compatibility.Check <PudgeRobot>(this, a).IsInvisible)
            .Select(actor => new HeroData
                    (
                        actor is PudgeRobot ? HeroType.Pudge : HeroType.Slardar,
                        Actor.World.GetEngine <ICommonEngine>().GetAbsoluteLocation(actor.ObjectId)
                    ))
            .Where(h => Geometry.Distance(h.Location.ToPoint3D(), actorLocation) <
                   Actor.Rules.VisibilityRadius * Actor.DoubleDamageFactor || InWardScope(h.Location.ToPoint3D()))
            .ToList());
 }
コード例 #10
0
        public UnitResponse ProcessCommand(object _command)
        {
            if (actor.IsDisabled)
            {
                return(UnitResponse.Denied());
            }
            var command = Compatibility.Check <IDaggerCommand>(this, _command);

            if (command.MakeDagger)
            {
                actor.Dagger(command.DaggerDestination);
                return(UnitResponse.Accepted(0.1));
            }
            return(UnitResponse.Denied());
        }
コード例 #11
0
ファイル: WardUnit.cs プロジェクト: FoKycHuK/CVARC
        public UnitResponse ProcessCommand(object _command)
        {
            if (actor.IsDisabled)
            {
                return(UnitResponse.Denied());
            }
            var command = Compatibility.Check <IWardCommand>(this, _command);

            if (command.MakeWard)
            {
                actor.SpawnWard();
                return(UnitResponse.Accepted(0.1));
            }
            return(UnitResponse.Denied());
        }
コード例 #12
0
ファイル: HexMovUnit.cs プロジェクト: penguin-of-linux/homm
        public UnitResponse ProcessCommand(object _command)
        {
            var movement = Compatibility.Check <IHexMovCommand>(this, _command).Movement;

            if (movement == null)
            {
                return(UnitResponse.Denied());
            }

            var commandDuration = rules.MovementDuration * actor.VelocityModifier;

            actor.World.Clocks.AddTrigger(new OneTimeTrigger(commandDuration,
                                                             () => actor.Location = movement.Turn(actor.Location)));

            return(UnitResponse.Accepted(commandDuration));
        }
コード例 #13
0
        public UnitResponse ProcessCommand(object command)
        {
            var movement = Compatibility.Check <IHexMovCommand>(this, command).Movement;

            if (movement == null)
            {
                return(UnitResponse.Denied());
            }

            var movementResult = movement.TryMoveHero(
                actor.World.HommEngine, actor.Player, actor.World.Round.Map);

            var newLocation      = movementResult.Item1;
            var movementDuration = movementResult.Item2;

            actor.World.Clocks.AddTrigger(actor.LocationTrigger = new LocationTrigger(
                                              actor.World.Clocks.CurrentTime, movementDuration / 2, actor, newLocation));

            return(UnitResponse.Accepted(double.PositiveInfinity));
        }
コード例 #14
0
        public UnitResponse ProcessCommand(object command)
        {
            var armyForGarrison = Compatibility.Check <IGarrisonCommand>(this, command).WaitInGarrison;

            if (armyForGarrison == null)
            {
                return(UnitResponse.Denied());
            }

            if (actor.IsDead)
            {
                return(UnitResponse.Accepted(HommRules.Current.GarrisonBuildDuration));
            }

            actor.World.HommEngine.Freeze(actor.ControllerId);
            actor.World.HommEngine.SetAnimation(actor.ControllerId, Animation.Idle);

            if (!CheckCommandCorrect(armyForGarrison))
            {
                return(UnitResponse.Accepted(HommRules.Current.GarrisonBuildDuration));
            }

            TakeUnitsAway(actor.Player, armyForGarrison);

            var garrison = FindGarrison(actor.Player.Location);

            if (garrison == null)
            {
                garrison = CreateGarrison(armyForGarrison, actor.Player);
            }
            else
            {
                garrison.Populate(armyForGarrison);
            }

            Debug(garrison);

            return(UnitResponse.Accepted(HommRules.Current.GarrisonBuildDuration));
        }
コード例 #15
0
ファイル: WADUnit.cs プロジェクト: FoKycHuK/CVARC
        public UnitResponse ProcessCommand(object _command)
        {
            if (actor.IsDisabled)
            {
                return(UnitResponse.Denied());
            }
            var command = Compatibility.Check <IGameCommand>(this, _command).GameMovement;

            if (command == null)
            {
                return(UnitResponse.Denied());
            }

            var hasteFactor = actor.HasteFactor;
            var eps         = 0.01;

            if (command.Range <= 0 && Math.Abs(command.Angle) < eps && command.WaitTime <= 0)
            {
                Wait();
                return(UnitResponse.Accepted(1));
            }
            if (command.WaitTime > eps)
            {
                Wait();
                return(UnitResponse.Accepted(command.WaitTime));
            }
            if (command.Range > eps)
            {
                var movementTime = Move(command.Range, hasteFactor);
                return(UnitResponse.Accepted(movementTime));
            }
            if (Math.Abs(command.Angle) > eps)
            {
                var rotationTime = Rotate(command.Angle);
                return(UnitResponse.Accepted(rotationTime));
            }
            return(UnitResponse.Accepted(0.025));
        }
コード例 #16
0
ファイル: HexMovUnit.cs プロジェクト: FoKycHuK/CVARC
        public UnitResponse ProcessCommand(object command)
        {
            Debugger.Log("Enter process command");

            var movement = Compatibility.Check <IHexMovCommand>(this, command).Movement;

            if (movement == null)
            {
                return(UnitResponse.Denied());
            }
            Debugger.Log("Accepted HexMovCommand");

            if (actor.IsDead)
            {
                return(UnitResponse.Accepted(movement.WaitDuration > 0
                    ? movement.WaitDuration
                    : HommRules.Current.MovementDuration));
            }

            var movementDuration = movement.Apply(actor);

            return(UnitResponse.Accepted(movementDuration + 0.001));
        }
コード例 #17
0
ファイル: WADUnit.cs プロジェクト: FoKycHuK/CVARC
 public WADUnit(IActor actor)
 {
     this.actor = Compatibility.Check <IWADRobot>(this, actor);
     rules      = Compatibility.Check <IWADRules>(this, this.actor.Rules);
 }
コード例 #18
0
ファイル: HexMovUnit.cs プロジェクト: penguin-of-linux/homm
 public HexMovUnit(IHexMovRobot actor)
 {
     this.actor = actor;
     this.rules = Compatibility.Check <IHexMovRules>(this, actor.Rules);
 }
コード例 #19
0
 public void Initialize(IActor controllableActor)
 {
     slardar = Compatibility.Check <Slardar>(this, controllableActor);
 }
コード例 #20
0
        public void DefineKeyboardControl(IKeyboardController _pool, string controllerId)
        {
            var pool = Compatibility.Check <KeyboardController <PudgeCommand> >(this, _pool);

            if (controllerId == TwoPlayersId.Left)
            {
                pool.Add(Keys.W, () => new PudgeCommand {
                    GameMovement = new GameMovement {
                        Range = keyboardMovementRange
                    }
                });
                pool.Add(Keys.A,
                         () => new PudgeCommand {
                    GameMovement = new GameMovement {
                        Angle = keyboardRotationAngle
                    }
                });
                pool.Add(Keys.D,
                         () => new PudgeCommand {
                    GameMovement = new GameMovement {
                        Angle = -keyboardRotationAngle
                    }
                });
                pool.Add(Keys.Space, () => new PudgeCommand {
                    MakeHook = true
                });
                pool.Add(Keys.F, () => new PudgeCommand {
                    MakeDagger        = true,
                    DaggerDestination = new DaggerDestinationPoint(0, 0)
                });
                pool.Add(Keys.G, () => new PudgeCommand {
                    MakeWard = true
                });
            }
            else
            {
                pool.Add(Keys.I, () => new PudgeCommand {
                    GameMovement = new GameMovement {
                        Range = MovementRange
                    }
                });
                pool.Add(Keys.J,
                         () => new PudgeCommand {
                    GameMovement = new GameMovement {
                        Angle = keyboardRotationAngle
                    }
                });
                pool.Add(Keys.L,
                         () => new PudgeCommand {
                    GameMovement = new GameMovement {
                        Angle = -keyboardRotationAngle
                    }
                });
                pool.Add(Keys.Enter, () => new PudgeCommand {
                    MakeHook = true
                });
            }
            pool.StopCommand = () => new PudgeCommand {
                GameMovement = new GameMovement {
                    WaitTime = WaitDuration
                }
            };
        }
コード例 #21
0
ファイル: HommRules.cs プロジェクト: FoKycHuK/CVARC
        public void DefineKeyboardControl(IKeyboardController _pool, string controllerId)
        {
            var pool = Compatibility.Check <KeyboardController <HommCommand> >(this, _pool);

            if (controllerId == TwoPlayersId.Left)
            {
                pool.Add(Keys.W, () => new HommCommand {
                    Movement = new HexMovement(Direction.Up)
                });
                pool.Add(Keys.S, () => new HommCommand {
                    Movement = new HexMovement(Direction.Down)
                });
                pool.Add(Keys.A, () => new HommCommand {
                    Movement = new HexMovement(Direction.LeftDown)
                });
                pool.Add(Keys.D, () => new HommCommand {
                    Movement = new HexMovement(Direction.RightDown)
                });
                pool.Add(Keys.Q, () => new HommCommand {
                    Movement = new HexMovement(Direction.LeftUp)
                });
                pool.Add(Keys.E, () => new HommCommand {
                    Movement = new HexMovement(Direction.RightUp)
                });

                pool.Add(Keys.Space, () => new HommCommand {
                    HireOrder = new HireOrder(5)
                });

                pool.Add(Keys.X, () => new HommCommand
                {
                    WaitInGarrison = new Dictionary <UnitType, int> {
                        { UnitType.Militia, 5 }
                    }
                });
            }
            else if (controllerId == TwoPlayersId.Right)
            {
                pool.Add(Keys.I, () => new HommCommand {
                    Movement = new HexMovement(Direction.Up)
                });
                pool.Add(Keys.K, () => new HommCommand {
                    Movement = new HexMovement(Direction.Down)
                });
                pool.Add(Keys.J, () => new HommCommand {
                    Movement = new HexMovement(Direction.LeftDown)
                });
                pool.Add(Keys.L, () => new HommCommand {
                    Movement = new HexMovement(Direction.RightDown)
                });
                pool.Add(Keys.U, () => new HommCommand {
                    Movement = new HexMovement(Direction.LeftUp)
                });
                pool.Add(Keys.O, () => new HommCommand {
                    Movement = new HexMovement(Direction.RightUp)
                });

                pool.Add(Keys.Enter, () => new HommCommand {
                    HireOrder = new HireOrder(5)
                });

                pool.Add(Keys.M, () => new HommCommand
                {
                    WaitInGarrison = new Dictionary <UnitType, int> {
                        { UnitType.Militia, 5 }
                    }
                });
            }

            pool.StopCommand = () => new HommCommand {
                Movement = new HexMovement(waitDuration: 0.1)
            };
        }
コード例 #22
0
ファイル: HookUnit.cs プロジェクト: FoKycHuK/CVARC
 public HookUnit(IActor actor)
 {
     this.actor = Compatibility.Check <IHookRobot>(this, actor);
     rules      = Compatibility.Check <IHookRules>(this, actor.Rules);
     hook       = new Hook(this.actor, rules);
 }
コード例 #23
0
ファイル: WardUnit.cs プロジェクト: FoKycHuK/CVARC
 public WardUnit(IActor actor)
 {
     this.actor = Compatibility.Check <IWardRobot>(this, actor);
 }
コード例 #24
0
 public DaggerUnit(IActor actor)
 {
     this.actor = Compatibility.Check <IDaggerRobot>(this, actor);
 }