// ------------------------------------------------------------------------------------ //
    public void onTouchBegan(GameTouchController gameTouchController, GameTouchParams gameTouchParams)
    {
        // Check active unit
        if (gameTouchParams.touchGameObject.tag.Equals(UnitBase.UNIT_TAG))
        {
            UnitBase unit = gameTouchParams.touchGameObject.GetComponent<UnitBase>();
            if (unit != null && unit.isUnitMaster())
            {
                if (activeUnit != null && activeUnit.Equals(unit))
                {
                    activeUnit.setActive(false);
                    activeUnit = null;
                }
                else
                {
                    setNewActiveUnit(unit);
                }

                return;
            }
        }

        // Move active unit if not return
        if (activeUnit != null) {
            ((UnitMasterBase) activeUnit).moveAtPosition(gameTouchParams.touchPosition);
        }
    }
示例#2
0
        protected WidgetBase(UnitBase unit)
        {
            Unit = unit;

            // by setting the widget's datacontext to the unit, we enable WPF's binding listeners
            DataContext = unit;
        }
示例#3
0
 public IEnumerator AttackUnitBase(UnitBase targetUnitBase, int damage)
 {
     isAttacking = true;
     var fort = targetUnitBase as Fort;
     if (fort)
     {
         var fortIndex = fort.index;
         var fortLife = fort.rebornsLeft;
         Element targetElement;
         while (Data.GamePaused || !Data.Replay.Elements.TryGetValue(fortIndex, out targetElement) || (targetElement as Fort).life != fortLife)
             yield return null;
         targetUnitBase = targetElement as UnitBase;
     }
     var targetPosition = targetUnitBase.transform.WorldCenterOfElement();
     yield return StartCoroutine(AimAtPosition(targetPosition));
     targetAmmo -= AmmoOnce();
     if (targetUnitBase)
     {
         yield return StartCoroutine(FireAtUnitBase(targetUnitBase));
         targetUnitBase.targetHP -= damage;
         Data.Replay.TargetScores[team] += Constants.Score.PerDamage * damage;
     }
     else
         yield return StartCoroutine(FireAtPosition(targetPosition));
 }
 public static void addToBucket(UnitBase unitAdded, int team)
 {
     if (team == 1)
         Team1Bucket.Add(unitAdded);
     else
         Team2Bucket.Add(unitAdded);
 }
示例#5
0
    public void ApplySteering(UnitBase[] units)
    {
        // accumulate forces and apply to the creep
        if(GetComponent<UnitBase>().attacking)
            return;
        Vector2 targetForce = target-u.position;

        targetForce = targetForce.normalized * maxSpeed;
        targetForce -= vel;
        targetForce = Vector2.ClampMagnitude(targetForce, maxForce);

        Vector2 attract = Attract(units);
        Vector2 sep = Sep(units);
        if(attract != Vector2.zero){
            targetForce *= 0.7f;
            sep *= 0.2f;
            acc += sep;
            acc += attract;

        }else{
            targetForce *= 0.5f;
            sep *= 0.5f;
            acc += targetForce;
            acc += sep;
        }
        vel += acc;

        vel = Vector2.ClampMagnitude(vel, maxSpeed);
        u.position += vel;

        acc = Vector2.zero;
    }
示例#6
0
 public void Initialize(UnitBase attacker, UnitBase targetUnitBase, Level bombLevel)
 {
     this.attacker = attacker;
     this.targetUnitBase = targetUnitBase;
     targetPosition = targetUnitBase.transform.WorldCenterOfElement();
     level = bombLevel;
 }
示例#7
0
    public void CheckNeighbors(UnitBase[] units)
    {
        targets.Clear();

        foreach(UnitBase unit in units){
            if(unit.GetComponent<PlayerManager>()&&unit.u.owner == u.owner){
                float dist = Vector2.Distance(unit.u.position, u.position);
                if(dist - unit.u.displaySize < GetComponent<UnitBase>().attackRadius){
                    // we are within the attack radius!
                    unit.temporaryDistance = dist;
                    targets.Add(unit);
                }
            }
        }
        targets.Sort(delegate(UnitBase p1, UnitBase p2)
            {
                return (p1.temporaryDistance > p2.temporaryDistance)?-1:1;
            }
        );
        GetComponent<UnitBase>().attacking = false;
        if(targets.Count > 0){
            // if the nearest target is our player, then heal to the maximum
            if(targets[0].GetComponent<PlayerManager>() && targets[0].u.owner == u.owner){
                // heal!
                GetComponent<PhotonView>().RPC("SetCooldown", PhotonTargets.AllBuffered, u.attackCooldown);
                targets[0].GetComponent<PhotonView>().RPC("SetHealth", PhotonTargets.AllBuffered, targets[0].u.health+targets[0].u.fullHealth*0.5f);
            }else if(targets[0].u.owner != u.owner){
                GetComponent<UnitBase>().attacking = true;
                GetComponent<UnitBase>().AttackTarget(targets[0]);
            }
        }
    }
示例#8
0
	public IBattleObject FindEnemy(UnitBase finder) {
		foreach (var unit in units) {
			if (unit is MilitaryUnit && unit != finder)
				return unit;
		}
		return null;
	}
示例#9
0
 public void addUnit(UnitBase unit)
 {
     if (!myUnitList.Contains(unit)) {
         myUnitList.Add(unit);
         numUnitsInGroup++;
     }
 }
示例#10
0
文件: EnemyUnit.cs 项目: rinat/battle
 public EnemyUnit(World world, UnitBase target)
     : base(world, WorldLaw.EnemyUnitCreationSpeed,
     WorldLaw.DefaultEnemyLifeCount)
 {
     State = EnemyState.Running;
     Target = target;
 }
示例#11
0
 public BulletUnit(World world, PointF point, UnitBase sender)
     : base(world, WorldLaw.BulletUnitCreationSpeed,
     WorldLaw.DefaultEnemyLifeCount)
 {
     SetLocation(point.X, point.Y);
     Sender = sender;
     BulletState = BulletUnitState.Running;
 }
 public void AttackUnit(UnitBase unit)
 {
     if (dealDamage(ActiveUnit, unit))
     {
         positionToClean = ActiveUnit.Position;
         ActivateNextUnit(NextTurnQueue);
     }
 }
示例#13
0
        public StatementWidget(UnitBase unit)
            : base(unit)
        {
            // Workaround that fixes WPF DataBinding problem where values are properly bound but not UI updated
            SubscribeDataBinding();

            InitializeComponent();
        }
    // ------------------------------------------------------------------------------------ //
    public override void initialize(UnitBase unit)
    {
        base.initialize(unit);

        _unit.registerObserver((IUnitCollisionObserver) this);
        _unitMaster.registerObserver((IUnitMasterObserver) this);

        deltaPosition = _unitMaster.UnitPosition - _unit.UnitPosition;
    }
示例#15
0
 protected override IEnumerator FireAtUnitBase(UnitBase targetUnitBase)
 {
     ++explosionsLeft;
     (Instantiate(Resources.Load("Bomb"), transform.position, transform.rotation) as GameObject).GetComponent<BombManager>().Initialize(this, targetUnitBase, BombManager.Level.Small);
     isAttacking = false;
     while (explosionsLeft > 0)
         yield return null;
     --Data.Replay.AttacksLeft;
 }
示例#16
0
    // ------------------------------------------------------------------------------------ //
    public override void initialize(UnitBase unit)
    {
        _positionStart = _unitMaster.UnitPosition;

        moveDistance = Vector3.Distance(_positionStart, _positionEnd);
        moveTime = moveDistance / speed;

        _unitMaster.registerObserver((IUnitCollisionObserver) this);
    }
    // ------------------------------------------------------------------------------------ //
    private void setNewActiveUnit(UnitBase unit)
    {
        if (activeUnit != null) {
            activeUnit.setActive(false);
        }

        activeUnit = unit;
        activeUnit.setActive(true);
    }
 ///<summer>
 /// When called it adds a UnitBase instance to the PartyMembers list.
 ///</summer>
 public void JoinParty(UnitBase plr)
 {
     if (!partyMembers.Contains(plr))
     {
         partyMembers.Add(plr);
     }
     else
         throw new System.ArgumentException("Already exists in " + this.ToString(), plr.gameObject.name);
 }
示例#19
0
 public void CloneTo(UnitBase unitbase)
 {
     unitbase.Name = this.Name;
     unitbase.Armor = this.Armor;
     unitbase.EnemyLayer = this.EnemyLayer;
     unitbase.GroundLayer = this.GroundLayer;
     unitbase.WallLayer = this.WallLayer;
     unitbase.MaxHP = this.MaxHP;
     unitbase.HP = this.HP;
 }
 public override void Apply(UnitBase caster, UnitBase unit)
 {
     var statusToAdd = ScriptableObject.CreateInstance<Status>();
     statusToAdd.Duration = status.Duration;
     statusToAdd.Parmanent = status.Parmanent;
     statusToAdd.Removable = status.Removable;
     statusToAdd.Rule = status.Rule;
     statusToAdd.Type = status.Type;
     unit.Statuses.Add(statusToAdd);
 }
示例#21
0
 public static void setAttackHUD(UnitBase unit)
 {
     activeButtons = 0;
     foreach(Attack x in unit.attacks)
     {
         setButtonText(activeButtons, unit.attacks[activeButtons].aName);
         setButtonActive(activeButtons, true);
         activeButtons++;
     }
 }
示例#22
0
 public IEnumerator Supply(UnitBase target, int fuel, int ammo, int metal)
 {
     var elapsedTime = Mathf.Max((fuel * Settings.Replay.FuelMultiplier + ammo * Settings.Replay.AmmoMultiplier + metal * Settings.Replay.MetalMultiplier) / Settings.Replay.SupplyRate, 0.1f);
     StartCoroutine(Beam(target, elapsedTime, BeamType.Supply));
     yield return new WaitForSeconds((target.transform.WorldCenterOfElement() - Beamer.position).magnitude / Settings.Replay.BeamSpeed);
     target.FlashingOn();
     var effectedFuel = 0;
     var effectedAmmo = 0;
     var effectedMetal = 0;
     for (float t, startTime = Time.time; (t = (Time.time - startTime) / elapsedTime) < 1;)
     {
         if (!Data.GamePaused)
         {
             var deltaFuel = Mathf.RoundToInt(fuel * t - effectedFuel);
             if (deltaFuel > 0)
             {
                 targetFuel -= deltaFuel;
                 target.targetFuel += deltaFuel;
                 effectedFuel += deltaFuel;
             }
             var deltaAmmo = Mathf.RoundToInt(ammo * t - effectedAmmo);
             if (deltaAmmo > 0)
             {
                 targetAmmo -= deltaAmmo;
                 target.targetAmmo += deltaAmmo;
                 effectedAmmo += deltaAmmo;
             }
             var deltaMetal = Mathf.RoundToInt(metal * t - effectedMetal);
             if (deltaMetal > 0)
             {
                 targetMetal -= deltaMetal;
                 target.targetMetal += deltaMetal;
                 effectedMetal += deltaMetal;
             }
         }
         yield return null;
     }
     targetFuel -= fuel - effectedFuel;
     target.targetFuel += fuel - effectedFuel;
     targetAmmo -= ammo - effectedAmmo;
     target.targetAmmo += ammo - effectedAmmo;
     targetMetal -= metal - effectedMetal;
     target.targetMetal += metal - effectedMetal;
     target.FlashingOff();
     string message;
     if (metal == 0)
         if (ammo == 0)
             message = fuel > 0 ? "F: +" + fuel : "0";
         else
             message = (fuel > 0 ? "F: +" + fuel + "  " : "") + "A: +" + ammo;
     else
         message = (fuel > 0 ? "F: +" + fuel + "  " : "") + (ammo > 0 ? "A: +" + ammo + "  " : "") + "M: +" + metal;
     yield return StartCoroutine(Data.Replay.Instance.ShowMessageAt(target, message));
     --Data.Replay.SuppliesLeft;
 }
示例#23
0
    // Update is called once per frame
    void Update()
    {

        //Selection
        if (Input.GetMouseButtonDown(0))
        {
            //If no units are selected
            if(Equals(Selector.selected, null))
            {
                //If we are hovering a possible unit
                if(Selector.hovered != null)
                {
                    //Hover Over a friendly unit shows the selection circle
                    int layerValue = (1 << Selector.hovered.layer);
                    if ((layerValue & currentAllyLayer.value) > 0)
                    {
                        unit1 = Selector.hovered.GetComponent<UnitBase>();
                        selectScript.setSelected(unit1.unit);
                        AtkHUD.setAttackHUD(unit1);
                    }
                }
                //TODO
                //Sets the button names and activates them
            }

            //UnitPreviously selected may be unselected only if no actions have been taken already
            else if (!EventSystem.current.IsPointerOverGameObject() && !Equals(unit1, null) && !unit1.hasActed && !unit1.hasMoved)
            {
                //Immediatly Select another unit
                if (Selector.hovered != null)
                {
                    //Hover Over a friendly unit shows the selection circle
                    int layerValue = (1 << Selector.hovered.layer);
                    if ((layerValue & currentAllyLayer.value) > 0)
                    {
                        Selector.clearTargetted(UnitHandler.unit1);
                        unit1 = Selector.hovered.GetComponent<UnitBase>();
                        selectScript.setSelected(unit1.unit);
                    }
                }

                //We want to unselect a selected unit
                clearUnit(UnitHandler.unit1);
                Debug.Log("Unselected");
            }
            //Mouse is over menu
            else
            {
                Debug.Log("OverMenu!");

            }
        }

    }
示例#24
0
文件: EnemyUnit.cs 项目: rinat/battle
        public EnemyUnit(World world, Point position, UnitBase target)
            : base(world, WorldLaw.EnemyUnitCreationSpeed,
            WorldLaw.DefaultEnemyLifeCount)
        {
            State = EnemyState.Running;
            Target = target;

            SetLocation(position.X, position.Y);

            m_prevLocation.X = position.X;
            m_prevLocation.Y = position.Y;
        }
示例#25
0
 // todo: need refactoring
 private void TryAddScore(UnitBase sender, UnitBase deadOn)
 {
     var possiblePlayer = sender as PlayerUnit;
     var possibleEnemy = deadOn as EnemyUnit;
     if (possiblePlayer != null &&
         possibleEnemy != null)
     {
         possiblePlayer.Score.Count += 1;
         if ((possiblePlayer.Score.Count % WorldLaw.LevelUpThreshold) == 0)
         {
             sender.World.WorldState.LevelUp = true;
         }
     }
 }
示例#26
0
 public void IssueOrder(Order order)
 {
     foreach (var sel in currentSelection)
     {
         UnitBase    b = sel as UnitBase;
         DonateOrder d = order as DonateOrder;
         if (d != null && (b == null || !b.canDonate))
         {
             continue;
         }
         sel.SetOrder(order);
     }
     ClearSelection();
 }
示例#27
0
 public AoeField(UnitBase caster, AoeRegion region, float duration, float interval, List <BuffEmitter> emitters)
 {
     Caster      = caster;
     mRegion     = region;
     Interval    = interval;
     Duration    = duration;
     mElapseTime = 0;
     mCdTime     = 0;
     for (int i = 0; i < emitters.Count; ++i)
     {
         emitters[i].Caster = caster;
     }
     BuffEmitters = emitters;
 }
示例#28
0
    // helper function
    public UnitBase findNearestUnit(Vector3 destination)
    {
        UnitBase nearestUnit = myUnitList[0];

        foreach (UnitBase t in myUnitList)
        {
            if (Vector3.Distance(nearestUnit.transform.position, destination) > Vector3.Distance(t.transform.position, destination))
            {
                nearestUnit = t;
            }
        }

        return(nearestUnit);
    }
 protected virtual void DamageFunc(UnitBase unitBase)
 {
     if (MultyManager.Inst != null)
     {
         if (unitBase.photonView != null && !unitBase.photonView.isMine)
         {
             unitBase.photonView.RPC("GetDamage", PhotonTargets.AllBufferedViaServer, m_nValue);
         }
     }
     else
     {
         unitBase.GetDamage(m_nValue);
     }
 }
示例#30
0
    protected override void DoDamage(UnitBase unitToDealDamage)
    {
        //Añado este if para el count de honor del samurai
        if (currentFacingDirection == FacingDirection.North && unitToDealDamage.currentFacingDirection == FacingDirection.South ||
            currentFacingDirection == FacingDirection.South && unitToDealDamage.currentFacingDirection == FacingDirection.North ||
            currentFacingDirection == FacingDirection.East && unitToDealDamage.currentFacingDirection == FacingDirection.West ||
            currentFacingDirection == FacingDirection.West && unitToDealDamage.currentFacingDirection == FacingDirection.East
            )
        {
            LM.honorCount++;
        }

        base.DoDamage(unitToDealDamage);
    }
示例#31
0
        protected override void Awake()
        {
            if (this.unit == null)
            {
                this.unit       = this.transform.GetComponent <UnitBase>();
                this.controller = this.unit.controller;
            }

            this.FindUI(this.transform, UIValues.Unit.UNITUI);
            base.Awake();

            if (this._spCircle == null)
            {
                this._spCircle = this.transform.Find(UIValues.Unit.SELECTIONCIRCLE).GetComponent <SpriteRenderer>();
            }
            this._spCircle.gameObject.SetActive(false);

            if (this._btnEnd == null)
            {
                this._btnEnd = this.FindButton(this._tSelected, UIValues.Unit.ENDBUTTON);
            }

            if (this._btnCancel == null)
            {
                this._btnCancel = this.FindButton(this._tSelected, UIValues.Unit.CANCELBUTTON);
            }
            this._btnCancel.gameObject.SetActive(false);

            if (this._btnAttack == null)
            {
                this._btnAttack = this.FindButton(this._tSelected, UIValues.Unit.ATTACKBUTTON);
            }

            if (this._btnMove == null)
            {
                this._btnMove = this.FindButton(this._tSelected, UIValues.Unit.MOVEBUTTON);
            }

            if (this._btnFinishMove == null)
            {
                this._btnFinishMove = this.FindButton(this._tSelected, "Finish_BTN");
            }
            this._btnFinishMove.gameObject.SetActive(false);

            if (this._textInfo == null)
            {
                this._textInfo = this._tHover.Find(UIValues.Unit.INFOTEXT).GetComponent <Text>();
            }
        }
示例#32
0
 public override void Action(UnitBase _base)
 {
     if (_base.SelfFunction)
     {
         _base.Action(this);
         return;
     }
     if (CanMove(_base))
     {
         //Debug.Log("enter");
         transform.position       += MoveDir;
         _base.transform.position += MoveDir;
         _base.curmoveTime         = 0;
     }
 }
示例#33
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="MultiSelectionUnitDecorator" /> class.
        /// </summary>
        /// <param name="unit">A <see cref="Unit" />.</param>
        public MultiSelectionUnitDecorator(UnitBase unit)
        {
            this._unit         = unit;
            this._subordinates = new List <IUnitDecorator>();

            var higherUnit = Unit as HigherUnit;

            if (higherUnit != null)
            {
                foreach (var subordinate in higherUnit.Subordinates.OrderBy(subordinate => subordinate, UnitComparer))
                {
                    this._subordinates.Add(new MultiSelectionUnitDecorator(subordinate));
                }
            }
        }
示例#34
0
        public static string Format(long size, UnitBase @base = UnitBase.Base2, UnitStyle format = UnitStyle.Smart)
        {
            bool  neg      = size < 0;
            ulong fmt_size = size switch
            {
                // Math.Abs(long.MinValue) is out of range for long so we handle it separately
                long.MinValue => ((ulong)long.MaxValue) + 1,
                < 0 => (ulong)Math.Abs(size),
                _ => (ulong)size,
            };

            var formatted = Format(fmt_size, @base, format);

            return(neg ? "-" + formatted : formatted);
        }
    private void ServerHandleBaseDespawned(UnitBase unitBase)
    {
        bases.Remove(unitBase);

        if (bases.Count != 1)
        {
            return;
        }

        int playerId = bases[0].connectionToClient.connectionId; // only one player base left in list, so they must be the winner

        RpcGameOver($"Player {playerId}");

        ServerOnGameOver?.Invoke();
    }
示例#36
0
        /// <summary>
        /// 单位濒临死亡
        /// </summary>
        /// <param name="unit">死亡单位</param>
        /// <param name="slayer">攻击者</param>
        /// <returns>是否进入死亡</returns>
        public static bool OnUnitWillDie(UnitBase unit, UnitBase slayer)
        {
#if DEBUG
            Debug.LogFormat("OnUnitWillDie unit = {0} slayer = {1} ", unit.ID, slayer.ID);
#endif
            bool res = true;
            for (int i = mUnitWillDieList.Count - 1; i >= 0; --i)
            {
                if (!mUnitWillDieList[i].OnUnitWillDie(unit, slayer))
                {
                    res = false;
                }
            }
            return(res);
        }
示例#37
0
        private static int CalculateFinalDamageAmount(UnitBase damageDealer, UnitBase target, float totalDamage, bool isCritical)
        {
            totalDamage *= damageDealer.Unit.damageModFromPassives;
            totalDamage *= target.Unit.damageTakenModFromPassives;

            if (!isCritical)
            {
                return(totalDamage < 0 ? 0 : Random.Range((int)(0.97f * totalDamage), (int)(1.03f * totalDamage)));
            }

            totalDamage = (int)(totalDamage * GlobalVariables.Instance.criticalDamageFactor);
            target.Unit.targetHasCrit = true;

            return(totalDamage < 0 ? 0 : Random.Range((int)(0.97f * totalDamage), (int)(1.03f * totalDamage)));
        }
示例#38
0
    void SendLocalPlayerData()
    {
        UnitBase localPlayer = PlayerController.Instance.localPlayer;

        if (localPlayer)
        {
            // send data at least once in two seconds
            if (PlayerController.Instance.HasCommand() || Time.time - lastTimestamp > 0.1)
            {
                localPlayer.ValidatePlayerData();
                PlayerUpdateMsg puMsg = new PlayerUpdateMsg(clientId, localPlayer.GetPlayerData(), PlayerController.Instance.PopCommands());
                SendToServer(JsonUtility.ToJson(puMsg));
            }
        }
    }
示例#39
0
    void GetTarget()
    {
        if (!m_Seeking)
        {
            StartCoroutine("Seek");
        }
        m_CurrentTarget = PickBestSuitableTarget();

        if (m_CurrentTarget)
        {
            StopCoroutine("Seek");
            m_Seeking = false;
            m_CurrentTarget.UnitDied += DropTarget;
        }
    }
示例#40
0
 private void Update()
 {
     _spawnTimer += Time.deltaTime;
     if (_currentSpawns < _maxSimultaneousSpawns && (MaxSpawns > 0 || _endlessSpawn) && _spawnTimer > SpawnCooldown && (!_ActivatorExists || Activator.Active))
     {
         UnitBase enemy = Spawn();
         enemy.transform.position = transform.position;
         _spawnTimer = 0;
         _currentSpawns++;
         if (!_endlessSpawn)
         {
             MaxSpawns--;
         }
     }
 }
示例#41
0
    //Calculate damage when damage is not known
    public static int calculateDamage(UnitBase attacker, UnitBase defender, Attack attack)
    {
        float attackFactor = 1f;
        float defenceFactor = 1f;

        float damage = rollDamage(attack.roll, attack.dmg, attack.nDice);

        foreach(DamageType x in attack.getTypes())
        {
            attackFactor *= attacker.typeAtk[(int)x];
            defenceFactor *= defender.typeDef[(int)x];
        }

        return (int)(damage *= (attackFactor/defenceFactor));
    }
示例#42
0
        /// <summary>
        /// 更新物体的坐标和所属格子
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public void UpdateNode(UnitBase obj)
        {
            var cur = GetGridNodeByPosition(obj.position.x, obj.position.y);

            if (obj.mGridNode != null && obj.mGridNode != cur)
            {
                obj.mGridNode.Remove(obj);
                cur.Add(obj);
            }
            else
            {
                cur.Add(obj);
            }
            obj.mGridNode = cur;
        }
示例#43
0
 int SetControll(GameObject takeObject)
 {
     if (takeObject != null) {
         moveObject = takeObject;
         if (takeObject.name.Contains("Tower")) {
             turretScript = moveObject.GetComponent<TurretBase>();
             turretScript.takenOver = true;
             return 1;
         } else if (takeObject.name.Contains("Cat")) {
             unitScript = moveObject.GetComponent<UnitBase>();
             unitScript.takenOver = true; moveSpeed = unitScript.moveSpeed;
             return 2;
         } else return 0;
     } else return 0;
 }
示例#44
0
        private bool ExecuteMoveInternal(UnitBase unit, MobilityExtension.StepForwardMove move)
        {
            var dirVec = GetDirectionVector(unit.Facing);

            var pos = _gameWorldService.GetEntityPosition(unit);

            if (!pos.HasValue)
            {
                return(false);
            }

            var targetPos = (x : pos.Value.x + dirVec.x, y : pos.Value.y + dirVec.y);

            return(MoveUnitToPosition(unit, targetPos));
        }
示例#45
0
        private float CurrentRotationSet(UnitBase unit)
        {
            var currentRotation = MathHelper.WrapAngle(MathExt.Angle(unit.Movement.MovementVectorValue) - 0.786f);

            if (currentRotation < 0)
            {
                currentRotation = -currentRotation + 3.14f;
            }
            else
            {
                currentRotation = -(currentRotation - 3.14f);
            }
            currentRotation = MathHelper.ToDegrees(currentRotation);
            return(currentRotation);
        }
示例#46
0
 private static void TempestUpdater()
 {
     if (TempestManager.Tempest != null && TempestManager.Tempest.IsValid)
     {
         ItemPanel.GetItemPanel().Load();
         TempestHero = new Tempest();
         TempestHero.Init();
         UpdateManager.Unsubscribe(TempestUpdater);
         AutoMidas.GetNewInstance(TempestHero);
         DelayAction.Add(200, () =>
         {
             PushLaneSelector.GetInstance().Load();
         });
     }
 }
示例#47
0
    private void ServerHandleBaseDespawned(UnitBase unitBase)
    {
        bases.Remove(unitBase);

        if (bases.Count != 1)
        {
            return;
        }

        int playerID = bases[0].connectionToClient.connectionId;

        RpcGameOver($"Player {playerID}");

        ServerOnGameOver?.Invoke();
    }
示例#48
0
        private void SetupEnemyStatusBox(UnitBase clone, GameObject enemyGo)
        {
            var position    = enemyGo.transform.position;
            var newPosition = new Vector3(position.x, position.y + 2.25f, position.z);

            var statusBox = Instantiate(database.enemyStatusBox, newPosition,
                                        database.enemyStatusBox.rotation);

            statusBox.transform.SetParent(clone.Unit.transform);

            var statusBoxController = statusBox.GetComponentInChildren <StatusEffectControllerUI>();

            statusBoxController.member = clone;
            statusBoxController.Initialize();
        }
示例#49
0
        public UnitBase GetNearestEnemyUnit(Vector3 point, float distance = float.MaxValue)
        {
            UnitBase nearestEnemy = null;

            foreach (UnitBase enemy in enemyTeams[0].units)
            {
                float currentDistance = Vector3.Distance(point, enemy.transform.position);
                if (currentDistance < distance)
                {
                    distance     = currentDistance;
                    nearestEnemy = enemy;
                }
            }
            return(nearestEnemy);
        }
示例#50
0
    /// <summary>
    /// Creates a building object and returns that object. If specified type does not exists returns null.
    /// </summary>
    /// <param name="unitType"></param>
    /// <returns></returns>
    public UnitBase Create(UnitType unitType)
    {
        UnitBase unitBase = null;

        switch (unitType)
        {
        case UnitType.Barrack:

            unitBase = new Barracks(new UnitSpawnTileSelector())
            {
                XDimension             = 4,
                YDimension             = 4,
                MoveableUnitPrototypes =
                {
                    CreateMoveableUnit("soldier")
                }
            };

            break;

        case UnitType.PowerPlant:
            unitBase = new PowerPlants()
            {
                XDimension = 2,
                YDimension = 3
            };
            break;

        case UnitType.Camp:

            unitBase = new Camp(new UnitSpawnTileSelector())
            {
                XDimension             = 3,
                YDimension             = 2,
                MoveableUnitPrototypes =
                {
                    CreateMoveableUnit("camper"),
                    CreateMoveableUnit("soldier")
                }
            };
            break;

        default:
            Debug.LogError("This type of product is not specified.");
            break;
        }
        return(unitBase);
    }
示例#51
0
    public override void ReceiveDamage(int damageReceived, UnitBase unitAttacker)
    {
        if (parryOn && unitToParry != null)
        {
            particleParryAttack.SetActive(true);

            if (parryOn2)
            {
                if (unitAttacker == unitToParry)
                {
                    damageReceived = 0;
                    DoDamage(unitToParry);
                    UIM.RefreshHealth();
                    parryIcon.SetActive(false);
                }
                else if (unitToParry != null)
                {
                    if ((unitAttacker.currentFacingDirection == FacingDirection.North || unitAttacker.currentFacingDirection == FacingDirection.South &&
                         currentFacingDirection == FacingDirection.West || currentFacingDirection == FacingDirection.East)
                        ||
                        (unitAttacker.currentFacingDirection == FacingDirection.West || unitAttacker.currentFacingDirection == FacingDirection.East &&
                         currentFacingDirection == FacingDirection.North || currentFacingDirection == FacingDirection.South))
                    {
                        base.ReceiveDamage(damageReceived, unitAttacker);

                        DoDamage(unitToParry);
                        UIM.RefreshHealth();

                        parryIcon.SetActive(false);
                    }
                }
            }

            else if (unitAttacker == unitToParry)
            {
                damageReceived = 0;
                DoDamage(unitToParry);
                UIM.RefreshHealth();

                parryIcon.SetActive(false);
            }
        }

        else
        {
            base.ReceiveDamage(damageReceived, unitAttacker);
        }
    }
示例#52
0
 public void Wall(UnitBase unit)
 {
     unit.unitCounters.Add("ap", 1);
     unit.unitCounters.Add("apMax", 1);
     unit.unitCounters.Add("iniciative", 1);
     unit.unitCounters.Add("reqInfluence", 1);
     unit.unitCounters.Add("hp", 10);
     unit.unitCounters.Add("speed", 2);
     unit.unitCounters.Add("maxSpeed", 2);
     unit.unitCounters.Add("isEnemy", 0);
     unit.audioMenager = Instantiate(unit._audioMenager, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
     unit.audioMenager.GetComponent <AudioMenager>().initAudio("building");
     unit.unitDescription.setCardDescription("Ściana", "Zwykła ściana nic dodać nic ująć");
     unit.beforeEffects.Add(new InfluenceEffect(unit, Zone.frame(2), materialHolder));
     unit.afterEffects.Add(new AttackEffect(unit, new Zone(), materialHolder));
 }
示例#53
0
 public TeachBoxViewModel()
 {
     LengthUnitCollection = new ObservableCollection <UnitBase>()
     {
         new Millimeter(),
         new Micron(),
         new Nano()
     };
     AngleUnitCollection = new ObservableCollection <UnitBase>
     {
         new Degree(),
         new Radian(),
     };
     _currentLengthUint = LengthUnitCollection[0];
     _currentAngleUint  = AngleUnitCollection[0];
 }
示例#54
0
    public override void readFromNbt(NbtCompound tag)
    {
        base.readFromNbt(tag);

        this.fireCooldown = tag.getFloat("fireCooldown");
        MapObject obj = this.map.findMapObjectFromGuid <MapObject>(tag.getGuid("targetGuid"));

        if (obj is UnitBase)
        {
            this.target = (UnitBase)obj;
        }
        else
        {
            this.target = null;
        }
    }
示例#55
0
    void Start()
    {
        shopImage     = transform.Find("ShopImage").GetComponent <Image>();
        shopImageBack = transform.Find("ShopImageBack").GetComponent <Image>();
        text          = transform.Find("Text").GetComponent <TextMeshProUGUI>();
        hireCountText = transform.Find("HireCount").GetComponent <TextMeshProUGUI>();
        unitBase      = buildPrefab.GetComponent <UnitBase>();

        shopImage.fillAmount = 0;
        text.text           += $" {unitBase.price.meat}";
        startingAlpha        = shopImageBack.color.a;
        hireCount            = 0;
        hireCountText.text   = hireCount.ToString();

        Hide();
    }
示例#56
0
 public void GolompEnemy(UnitBase unit)
 {
     //Debug.Log("enemy load");
     unit.unitCounters.Add("ap", 0);
     unit.unitCounters.Add("apMax", 2);
     unit.unitCounters.Add("iniciative", 3);
     unit.unitCounters.Add("hp", 3);
     unit.unitCounters.Add("speed", 2);
     unit.unitCounters.Add("maxSpeed", 2);
     unit.unitCounters.Add("isEnemy", 1);
     unit.audioMenager = Instantiate(unit._audioMenager, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
     unit.audioMenager.GetComponent <AudioMenager>().initAudio("enemy");
     unit.unitDescription.setCardDescription("Nieumarly pryskacz", "Szybki i do tego pluje");
     unit.afterEffects.Add(new MoveEffect(unit, Zone.one(), materialHolder));
     unit.afterEffects.Add(new AttackEffect(unit, Zone.frame(2), materialHolder));
 }
示例#57
0
 public void BasicEnemy(UnitBase unit)
 {
     //Debug.Log("enemy load");
     unit.unitCounters.Add("ap", 0);
     unit.unitCounters.Add("apMax", 2);
     unit.unitCounters.Add("iniciative", 1);
     unit.unitCounters.Add("hp", 3);
     unit.unitCounters.Add("speed", 2);
     unit.unitCounters.Add("maxSpeed", 2);
     unit.unitCounters.Add("isEnemy", 1);
     unit.audioMenager = Instantiate(unit._audioMenager, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
     unit.audioMenager.GetComponent <AudioMenager>().initAudio("enemy");
     unit.unitDescription.setCardDescription("Nieumarly alien", "Jeden z pierwszych odkrytych nieumarłych lecz nieżywych ocalałych");
     unit.afterEffects.Add(new MoveEffect(unit, Zone.one(), materialHolder));
     unit.afterEffects.Add(new AttackEffect(unit, Zone.frame(1), materialHolder));
 }
示例#58
0
 public void CheckNeighbors(UnitBase[] units)
 {
     BuildTargetList();
     GetComponent<UnitBase>().attacking = false;
     if(targets.Count > 0){
         if(currentMode == Modes.HEAL && GetComponent<UnitBase>().attackCooldownCounter <= 0){
             Debug.Log("Healing");
             GetComponent<UnitBase>().attackCooldownCounter = u.attackCooldown;
             GetComponent<PhotonView>().RPC("SetCooldown", PhotonTargets.AllBuffered, u.attackCooldown);
             targets[0].GetComponent<PhotonView>().RPC("SetHealth", PhotonTargets.AllBuffered, targets[0].u.health + 20);
             lines.AddLine(u.pos3.Variation(1), targets[0].u.pos3.Variation(1), ourColor);
             return;
         }
         if(currentMode == Modes.ATTACK){
             GetComponent<UnitBase>().attackCooldownCounter = u.attackCooldown;
             GetComponent<UnitBase>().attacking = true;
             GetComponent<UnitBase>().AttackTarget(targets[0]);
         }
     }
 }
    public override void launchAttack()
    {
        target = null;
        Debug.Log("DEBUG: LaunchAttack Single Target");
        RaycastHit hit;

        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity, UnitHandler.currentEnnemyLayer))
        {
            Debug.Log("AttackConnected!");
            Debug.Log(hit.collider.transform.root.gameObject.GetComponent<UnitBase>().uName);
            target = UnitHandler.units.Find(x => x.getId() == hit.collider.transform.root.gameObject.GetInstanceID());
            target.printName();
            //If we have an active unit and an active target
            if (!(Equals(UnitHandler.unit1, null)))
            {
                //Unit 1 attacks his target
                setTargets(Effector.getTargets());
                if(target!= null)
                    UnitHandler.unit1.attackUnit(target, this);
                endAttack();
            }
        }
    }
示例#60
0
 /**********************************************/
 /*REMOVE UNITS FROM TEAM BUCKETS*/
 /*New turn starts for other team when all moves are done -- Might become a new function*/
 /********************************************************/
 public static void removeFromBucket(UnitBase unitRemoved, int team)
 {
     if (team == 1)
     {
         Team1Bucket.Remove(unitRemoved);
         if (Team1Bucket.Count == 0)
         {
             Debug.Log("No more units in 1");
             if (isTeam1Turn)
                 teamSwitch();
         }
     }
     else
     {
         Team2Bucket.Remove(unitRemoved);
         if (Team2Bucket.Count == 0)
         {
             Debug.Log("No more units in 2");
             if(!isTeam1Turn)
                 teamSwitch();
         }     
     }      
 }