示例#1
0
        //public IGameMapTileGroup GetTiles(Vector3Int worldPosition)
        //{
        //    // Convert our unity positioin to our map X,Y
        //    TranslateUnityXYToMapXY(worldPosition, out var mapX, out var mapY);

        //    // Calculate the array index for our given X,Y based on the map dimensions
        //    var index = mapY * GameMapWidth + mapX;

        //    // Return the tiles at our calculated index
        //    return GameMapTiles[index];
        //}

        #endregion


        #region Passibility & Movement Cost


        public MovementCost AreaMovementCostForUnit(IGameUnit unit, int mapX, int mapY, int areaWidth = 1, int areaHeight = 1)
        {
            // Sanity checks
            if (areaWidth < 1 || areaHeight < 1)
            {
                return(MovementCost.Impassable);
            }
            if (mapX < 0 || mapX >= GameMapWidth || mapY < 0 || mapY >= GameMapHeight)
            {
                return(MovementCost.Impassable);
            }

            // Starting values for our movement cost value
            var   areaMovementCost = float.MinValue;
            ulong areaInhibition   = 0;

            // Collect the tiles we're checking
            for (var x = mapX; x < mapX + areaWidth; x++)
            {
                for (var y = mapY; y < mapY + areaHeight; y++)
                {
                    // Check for collision from game objects or units.
                    FindMapObjectInBounds(out var foundObject, x, y);
                    if (foundObject != null && unit != foundObject)
                    {
                        if (foundObject is IGameUnit)
                        {
                            var otherUnit = foundObject as IGameUnit;
                            if (otherUnit.UnitFaction != unit.UnitFaction)
                            {
                                return(MovementCost.Impassable);
                            }
                        }
                    }

                    // Get the tile group in question
                    var tileIndex = y * GameMapWidth + x;
                    if (tileIndex < 0 || tileIndex >= GameMapTiles.Length || GameMapTiles[tileIndex] == null)
                    {
                        Debug.Log(String.Format("MovementCostForUnit tile index out of bounds or null: {0}. Map tile length: {1}", tileIndex, GameMapTiles.Length));
                        continue;
                    }

                    // Get the movement cost for this tile group
                    var movementCost = TileGroupMovementCostForUnit(unit, GameMapTiles[tileIndex]);

                    // And update our tile area parameters. For an area we use the LARGEST / WORST movement costs across multiple tile groups
                    // If any tile in an area is impassable then the entire area is impassable
                    if (!movementCost.IsPassable)
                    {
                        return(MovementCost.Impassable);
                    }
                    areaMovementCost = Math.Max(areaMovementCost, movementCost.Cost);
                    areaInhibition  += movementCost.Inhibition;
                }
            }

            // We have found the worst movement cost for the tile area we have. Return that
            return(new MovementCost(areaMovementCost, areaInhibition));
        }
示例#2
0
        public override void DoAction(IEventArgs args)
        {
            FreeRuleEventArgs fr     = (FreeRuleEventArgs)args;
            IGameUnit         player = GetPlayer(args);

            if (StringUtil.IsNullOrEmpty(count) || count.Equals("0"))
            {
                count = "0";
            }
            method = new SelectMethod(FreeUtil.ReplaceVar(exp, args));
            if (player != null)
            {
                FreeData       fd           = (FreeData)player;
                ItemPosition[] currentItems = fd.freeInventory.Select(method);
                fr.TempUse("current", fd);
                int c = FreeUtil.ReplaceInt(count, args);
                for (int i = 0; i < currentItems.Length; i++)
                {
                    ItemPosition ip = currentItems[i];
                    ip.SetCount(c);
                    ip.GetKey().SetCount(c);
                    ip.GetInventory().GetInventoryUI().UpdateItem(fr, ip.GetInventory(), ip);
                }
                fr.Resume("current");
            }
        }
示例#3
0
        public bool GetUnitAtCursor(out IGameUnit foundUnit)
        {
            var result = FindMapObjectInBounds(out var gameMapObject, _currentMousePosition.X, _currentMousePosition.Y);

            foundUnit = gameMapObject as IGameUnit;
            return(foundUnit != null);
        }
示例#4
0
            public virtual void Frame(ISkillArgs args, IGameUnit unit, int range)
            {
                if (con == null && !StringUtil.IsNullOrEmpty(condition))
                {
                    con = new ExpParaCondition(condition);
                }
                BaseEventArgs bea = (BaseEventArgs)args;

                bea.TempUse("give", unit);
                foreach (IGameUnit gu in args.GetGameUnits())
                {
                    if (((XYZPara.XYZ)gu.GetXYZ().GetValue()).Distance(((XYZPara.XYZ)unit.GetXYZ().GetValue())) <= range)
                    {
                        bea.TempUse("get", gu);
                        if (con == null || con.Meet(args))
                        {
                            effect.SetKey(this.key);
                            effect.SetSource(unit.GetID());
                            if (effect.GetTime() < 200)
                            {
                                effect.SetTime(200);
                            }
                            gu.GetUnitSkill().AddSkillEffect(effect);
                        }
                        bea.Resume("get");
                    }
                }
                bea.Resume("give");
            }
        public GameMapAbilityRange(IGameUnit unit, IAbility ability)
        {
            List <MapPoint> points;

            points = GenerateRadiusPoints(unit, ability);

            Points = points.AsReadOnly();
        }
        public PreviewMoveUnitState(IGameBattle gameBattle, IGameMap gameMap, IGameUnit unit, IUnitSummaryWindow unitSummaryWindow)
        {
            _gameBattle = gameBattle;
            _gameMap    = gameMap;

            _unit = unit;
            _unitSummaryWindow = unitSummaryWindow;
        }
示例#7
0
 public UnitSkill(IGameUnit unit)
 {
     this.skills  = new List <ISkill>();
     this.effects = new EffectManager();
     this.unit    = unit;
     this.removes = new List <ISkill>();
     this.adds    = new List <ISkill>();
 }
示例#8
0
 public ulong GetInhibitionScore(IGameUnit unit)
 {
     if (unit.GetAttribute(UnitAttribute.WalkingDamage) > TileHealth)
     {
         return(DestructionValue);
     }
     return(0);
 }
示例#9
0
 public ExecuteAbilityState(IGameBattle gameBattle, IGameUnit unitCasting, IAbility abilityTargeting, int targetX, int targetY)
 {
     _gameBattle       = gameBattle;
     _unitCasting      = unitCasting;
     _abilityTargeting = abilityTargeting;
     _targetX          = targetX;
     _targetY          = targetY;
 }
示例#10
0
        public MovingUnitState(IGameBattle gameBattle, IGameMap gameMap, IGameUnit unit, IGameMapMovementRoute route, IInputStateFactory inputStateFactory)
        {
            _gameBattle = gameBattle;
            _gameMap    = gameMap;
            _unit       = unit;
            _route      = route;

            _inputStateFactory = inputStateFactory;
        }
 public void UpdateSelectedUnit(IGameUnit newUnit, AbilityCategory category)
 {
     if (_unit == newUnit && _category == category)
     {
         return;
     }
     _unit     = newUnit;
     _category = category;
 }
        public IGameMap GameMap;                        // The game map reference


        public AbilityExecuteParameters(IGameUnit unit, IAbility ability, IGameMapObject target, IEnumerable <IGameMapObject> targets, MapPoint targetPoint, IGameMap gameMap)
        {
            UnitExecuting    = unit;
            AbilityExecuting = ability;
            Target           = target;
            AllTargets       = targets;
            TargetPoint      = targetPoint;
            GameMap          = gameMap;
        }
        public UnitSelectActionState(IGameBattle gameBattle, IGameMap gameMap, IGameUnit unit, IUnitActionWindow unitActionWindow, IInputStateFactory inputStateFactory)
        {
            _gameBattle       = gameBattle;
            _gameMap          = gameMap;
            _unit             = unit;
            _unitActionWindow = unitActionWindow;

            _inputStateFactory = inputStateFactory;
        }
        public TargetAbilityState(IGameBattle gameBattle, IGameMap gameMap, IGameUnit unitCasting, IAbility abilityTargeting, IInputStateFactory inputStateFactory)
        {
            _gameBattle       = gameBattle;
            _gameMap          = gameMap;
            _unitCasting      = unitCasting;
            _abilityTargeting = abilityTargeting;

            _inputStateFactory = inputStateFactory;
        }
示例#15
0
        public UnitSelectAbilityState(IGameBattle gameBattle, IGameUnit unit, AbilityCategory abilityCategory, IUnitAbilitiesWindow selectedUnitAbilitiesWindow, IInputStateFactory inputStateFactory)
        {
            _gameBattle          = gameBattle;
            _unit                = unit;
            _abilityCategory     = abilityCategory;
            _unitAbilitiesWindow = selectedUnitAbilitiesWindow;

            _inputStateFactory = inputStateFactory;
        }
示例#16
0
        public MoveUnitState(IGameBattle gameBattle, IGameMap gameMap, IGameUnit unit, IUnitSummaryWindow unitSummaryWindow, IInputStateFactory inputStateFactory)
        {
            _gameBattle = gameBattle;
            _gameMap    = gameMap;

            _unit = unit;
            _unitSummaryWindow = unitSummaryWindow;

            _inputStateFactory = inputStateFactory;
        }
        public void switchto(IGameUnit x)
        {
            this.current = x;

            // this is a continuation from
            // X:\jsc.svn\examples\actionscript\svg\FlashHeatZeeker\FlashHeatZeekerWithStarlingB2\ApplicationSprite.cs
            // 3300

            this.label2.Text = new { x.identity }.ToString();
        }
示例#18
0
 protected void Add(IGameUnit unit, IHandler handler)
 {
     if (handler != null)
     {
         handlers.Add(handler);
     }
     AddUnit(unit);
     unit.InvalidateEvent += Invalidate;
     engine.Add(unit);
 }
        public void switchto(IGameUnit x)
        {
            this.current = x;

            // this is a continuation from
            // X:\jsc.svn\examples\actionscript\svg\FlashHeatZeeker\FlashHeatZeekerWithStarlingB2\ApplicationSprite.cs
            // 3300

            this.label2.Text = new { x.identity }.ToString();
        }
示例#20
0
        public static bool CanAbilityTargetUnit(IGameUnit user, IGameUnit target, IAbility ability)
        {
            // Get the map points the ability can target
            var targetPoints = GetMapPointsAbilityTargets(ability, user).ToList();

            // See if there's any collision between those map points and the target
            var rangeCheck = targetPoints.Any(x => x.CollidesWith(target.MapPoint));

            return(rangeCheck);
        }
示例#21
0
        public override void DoAction(IEventArgs args)
        {
            FreeRuleEventArgs fr = (FreeRuleEventArgs)args;

            IGameUnit unit = GetPlayer(args);

            if (unit != null)
            {
                PlayerEntity p = ((FreeData)unit).Player;

                int             itemId = FreeUtil.ReplaceInt(weaponId, args);
                int             index  = FreeUtil.ReplaceInt(weaponKey, args);
                EWeaponSlotType st     = FreeWeaponUtil.GetSlotType(index);

                WeaponBaseAgent agent = null;
                if (index == 0)
                {
                    agent = p.WeaponController().HeldWeaponAgent;
                }
                else
                {
                    agent = p.WeaponController().GetWeaponAgent(st);
                }
                if (agent != null && agent.IsValid() && !FreeUtil.ReplaceBool(replace, args))
                {
                    return;
                }

                var scan = WeaponUtil.CreateScan(itemId);
                if (FreeUtil.ReplaceBool(fullAmmo, args))
                {
                    var weaponAllConfig = SingletonManager.Get <WeaponConfigManagement>().FindConfigById(itemId);
                    scan.Bullet         = weaponAllConfig.PropertyCfg.Bullet;
                    scan.ReservedBullet = weaponAllConfig.PropertyCfg.Bulletmax;
                }
                if (index == 0)
                {
                    p.WeaponController().PickUpWeapon(scan);
                }
                else
                {
                    p.WeaponController().ReplaceWeaponToSlot(st, scan);
                    if (p.stateInterface.State.CanDraw() && p.WeaponController().HeldSlotType == EWeaponSlotType.None)
                    {
                        p.WeaponController().TryArmWeaponImmediately(st);
                    }
                }
                SimpleProto message = new SimpleProto();
                message.Key = FreeMessageConstant.PlaySound;
                message.Ks.Add(2);
                message.Ins.Add((int)EAudioUniqueId.PickupWeapon);
                message.Bs.Add(true);
                FreeMessageSender.SendMessage(p, message);
            }
        }
示例#22
0
        public override void DoAction(IEventArgs args)
        {
            FreeRuleEventArgs fr = (FreeRuleEventArgs)args;

            IGameUnit unit = GetPlayer(args);

            if (unit != null)
            {
                PlayerEntity p = ((FreeData)unit).Player;


                int itemId = FreeUtil.ReplaceInt(weaponId, args);

                int index = FreeUtil.ReplaceInt(weaponKey, args);

                EWeaponSlotType st = FreeWeaponUtil.GetSlotType(index);

                Debug.LogFormat("add weapon: " + itemId + "," + index);
                Logger.Debug("add weapon to team " + p.playerInfo.Camp + " player " + p.playerInfo.PlayerName);

                SimpleProto message = new SimpleProto();
                if (index == 0)
                {
                    p.WeaponController().PickUpWeapon(WeaponUtil.CreateScan(itemId));
                    //p.bag.Bag.SetWeaponBullet(30);
                    //p.bag.Bag.SetReservedCount(100);
                }
                else
                {
                    p.WeaponController().ReplaceWeaponToSlot(st, WeaponUtil.CreateScan(itemId));

                    if (p.stateInterface.State.CanDraw() && p.WeaponController().HeldSlotType == EWeaponSlotType.None)
                    {
                        p.WeaponController().TryArmWeapon(st);
                    }

                    //SwitchWeaponAction.WeaponToHand(p, st);
                }

                message.Ins.Add(itemId);
                if (index > 0)
                {
                    message.Ins.Add((int)st);
                }
                else
                {
                    message.Ins.Add(-1);
                }

                message.Ks.Add(2);
                message.Key = FreeMessageConstant.ChangeAvatar;
                FreeMessageSender.SendMessage(p, message);
                //p.network.NetworkChannel.SendReliable((int)EServer2ClientMessage.FreeData, message);
            }
        }
示例#23
0
 public void Start(IGameUnit scene)
 {
     if (Enabled)
     {
         return;
     }
     this.scene             = scene;
     scene.InvalidateEvent += Invalidate;
     Invalidate();
     Enabled = true;
 }
示例#24
0
        public void RefreshMapCursor()
        {
            gameMapCursor.CursorEnabled = IsCursorEnabled;

            // WHen the cursor is turned off then remove any hovered units too
            if (!IsCursorEnabled)
            {
                CursorHoverObject       = null;
                CursorHoverUnit         = null;
                _lastCursorCellPosition = Vector3Int.one; // v3int.one is an impossible value so it's good as an always-invalid value for comparison when the cursor is enabled later on
            }
        }
        public override void DoAction(IEventArgs args)
        {
            if (addtimePara == null)
            {
                addtimePara = new IntPara(ParaConstant.PARA_ITEM_ADD_TIME, 0);
            }
            FreeRuleEventArgs fr = (FreeRuleEventArgs)args;

            if (StringUtil.IsNullOrEmpty(count))
            {
                count = INI_COUNT;
            }
            FreeItem fi = FreeItemManager.GetItem(fr, FreeUtil.ReplaceVar(key, args), FreeUtil.ReplaceInt(count, args));

            if (StringUtil.IsNullOrEmpty(name))
            {
                name = InventoryManager.DEFAULT;
            }
            IGameUnit player = GetPlayer(args);

            if (player != null)
            {
                FreeData fd = (FreeData)player;
                args.TempUse(ParaConstant.PARA_PLAYER_CURRENT, fd);
                args.TempUse(ParaConstant.PARA_ITEM, fi);

                args.TempUsePara(new StringPara("from", ChickenConstant.BagGround));

                if (action != null)
                {
                    action.Act(args);
                }

                if (fd.freeInventory.GetInventoryManager().GetInventory(FreeUtil.ReplaceVar(name, args)).AddItem((ISkillArgs)args, fi, true))
                {
                    //addtimePara.setValue(fr.room.getServerTime());
                    fi.GetParameters().AddPara(addtimePara);
                }
                else
                {
                    if (failAction != null)
                    {
                        fr.TempUse(ParaConstant.PARA_ITEM, fi);
                        failAction.Act(args);
                        fr.Resume(ParaConstant.PARA_ITEM);
                    }
                }

                fr.ResumePara("from");
                fr.Resume(ParaConstant.PARA_PLAYER_CURRENT);
                fr.Resume(ParaConstant.PARA_ITEM);
            }
        }
示例#26
0
        public Queue <AbilityExecuteParameters> CreateAbiltyQueue(IGameUnit user, IAbility abilityToExecute, IEnumerable <IGameMapObject> targets, MapPoint targetPoint, IGameMap gameMap)
        {
            // Create our action queue
            var abilityExecuteQueue = new Queue <AbilityExecuteParameters>();

            // For now we'll only target game units from the targets list
            var gameUnitTargets = targets.OfType <IGameUnit>().ToList();

            // Sanity check: If we _don't_ have any game units then
            if (!gameUnitTargets.Any())
            {
                return(abilityExecuteQueue);
            }


            // Create a counter-attack object for each target
            var targetCounterAttacks = gameUnitTargets.Where(x => abilityToExecute.CanBeCountered).Where(x => x.UnitFaction != user.UnitFaction).Select(counteringUnit =>
            {
                var counterAbility = GetAutoAttackAbility(counteringUnit, user);

                return(new
                {
                    CounterUnit = counteringUnit,
                    CounterAbility = counterAbility,
                    CounterRepeat = counterAbility != null ? DamageCalculator.RepeatCount(counterAbility, counteringUnit, user) : 0,
                });
            }).Where(x => x.CounterAbility != null).ToList();

            // We need the number of repeats total. This'll govern how many loops we do of filling our queue
            var userRepeatCount = gameUnitTargets.Select(target => DamageCalculator.RepeatCount(abilityToExecute, user, target)).Max();
            var maxRepeatCount  = targetCounterAttacks.Any() ? Math.Max(userRepeatCount, targetCounterAttacks.Max(x => x.CounterRepeat)) : userRepeatCount;

            // Pregen list
            var counterTargetsList = new List <IGameMapObject> {
                user
            };

            for (var i = 0; i < maxRepeatCount; i++)
            {
                // Add the user's action to the queue if they have this many repeats
                if (i < userRepeatCount)
                {
                    abilityExecuteQueue.Enqueue(new AbilityExecuteParameters(user, abilityToExecute, null, targets, targetPoint, gameMap));
                }
                // Then add all the counter attacks!
                foreach (var counterAttack in targetCounterAttacks.Where(x => i < x.CounterRepeat))
                {
                    abilityExecuteQueue.Enqueue(new AbilityExecuteParameters(counterAttack.CounterUnit, counterAttack.CounterAbility, user, counterTargetsList, user.MapPoint, gameMap));
                }
            }

            return(abilityExecuteQueue);
        }
示例#27
0
        public ulong GetInhibitionScoreForUnit(IGameUnit unit)
        {
            if (!Tiles.Any())
            {
                return(0);
            }

            ulong sum = 0;

            Tiles.Where(x => x != null).ForEach(x => sum += x.MapTileData.DestructionValue);
            return(sum);
        }
示例#28
0
 public Duel(IMeet <Duel> meet, IGameUnit winner)
 {
     if (meet.Players.Item1 == winner)
     {
         Winner = meet.Players.Item1;
         Loser  = meet.Players.Item2;
     }
     else
     {
         Winner = meet.Players.Item2;
         Loser  = meet.Players.Item1;
     }
 }
示例#29
0
        public virtual GameUnitSet Select(IEventArgs args, IGameUnit unit)
        {
            GameUnitSet resutl = new GameUnitSet();

            foreach (IGameUnit gu in args.GetGameUnits())
            {
                if (((XYZPara.XYZ)gu.GetXYZ().GetValue()).Distance(((XYZPara.XYZ)trigger.GetXYZ().GetValue())) <= range)
                {
                    resutl.AddGameUnit(gu);
                }
            }
            return(resutl);
        }
示例#30
0
 private string GenerateInfoText(int damage, IGameUnit target)
 {
     if (this is IEnemy)
     {
         string result = this.Name + " hit you for " + damage + " damage!";
         return(result);
     }
     else
     {
         string result = "You hit " + target.Name + " for " + damage + " damage!";
         return(result);
     }
 }
示例#31
0
    public IEnumerator Attack(float range, float delay)
    {
        yield return new WaitForSeconds(delay);

        GameObject ob = Node_IsNull.GetBBVar(ai.blackBoard, targetKey) as GameObject;
        if(ob!= null)
            target = ob.GetComponent<IGameUnit>();
        if (target != null)
        {
            target.changeHealth(GetDamage());

        }
    }
示例#32
0
        public void Hit(IGameUnit target)
        {
            int damage = this.Attack - (this.Attack * target.Defence) / 700;

            if (damage < 0)
            {
                damage = 0;
            }
            target.Health -= damage;
            string info = GenerateInfoText(damage, target);

            InfoPanel.AddInfo(info);
        }
示例#33
0
 public abstract void onActivate(IGameUnit caster);
示例#34
0
 public abstract void onChanel(IGameUnit caster);
示例#35
0
 public abstract void onRelease(IGameUnit caster);
	public GameUnitSelectableAdapter (IGameUnit unit)
	{
		m_unit = unit;
	}
		public CanWalkDecorator(IGameUnit unit,int width, int height)
		{
			m_decoratee = unit;
			m_width = width;
			m_height = height;
		}
示例#38
0
 //to chane functionality in a child class juste use the override
 //default way to call an attack
 public override void onActivate(IGameUnit caster)
 {
     //called onbuttondown
     StartCoroutine(caster.Attack(range, delay));
     StartCoroutine(attack());
 }
 public Node_Attack_Activate_Weapon(command weapon, IGameUnit caster)
 {
     m_weapon = weapon;
     m_caster = caster;
 }
示例#40
0
 protected void Init()
 {
     stats = this.gameObject.GetComponent<IGameUnit>();
     blackBoard = new Dictionary<string, System.Object>();
     //stats = this.gameObject.get
 }
示例#41
0
 //used for charging up
 public override void onChanel(IGameUnit caster)
 {
 }
示例#42
0
 //release charge up
 public override void onRelease(IGameUnit caster)
 {
 }
 public Node_Activate_Ability(command ability, IGameUnit caster)
 {
     m_ability = ability;
     m_caster = caster;
 }