Example #1
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="OurHitbox"></param>
    /// <param name="OtherHurtbox"></param>
    private void OurHitboxIntersectOtherHurtbox(EHHitbox OurHitbox, EHHitbox OtherHurtbox)
    {
        if (OurHitbox == null || OtherHurtbox == null)
        {
            return;
        }

        if (OtherHurtbox.HitboxActorComponent.bAnimationIsInvincible)
        {
            return;//Other character was invincible when we attempted to hit them, may in the future want to add some kind of wiff affect to indicate that you made contact but couldn't hurt them
        }

        EHDamageableComponent OtherDamageableComponent = OtherHurtbox.HitboxActorComponent.DamageableComponent;

        if (OtherDamageableComponent == null)
        {
            Debug.LogWarning("There is no Damageable component associated with the hurtbox we are intersecting");
            return;
        }
        if (AttackComponent == null)
        {
            Debug.LogWarning("There is no Attack component associated with our intersecting Hitbox");
            return;
        }
        AttackComponent.OnDamageableComponentIntersectionBegin(OtherDamageableComponent);
    }
Example #2
0
 private void Awake()
 {
     myAttackComponent = GetComponent <AttackComponent>();
     mySeeker          = GetComponent <Seeker>();
     myTargets         = new HashSet <GameObject>();
     myRigidbody2D     = GetComponent <Rigidbody2D>();
 }
    //每帧都会调用对应的实体
    public override void Execute(List <BasicEntity> entities)
    {
        foreach (BasicEntity e in entities)
        {
            AttackComponent  attack = e.GetComponent <AttackComponent> ();
            VoxelBlocks      map    = GameObject.Find("Voxel Map").transform.GetComponent <VoxelBlocks> ();
            AbilityComponent ab     = e.GetComponent <AbilityComponent> ();
            InputComponent   input  = e.GetComponent <InputComponent> ();
            StateComponent   ap     = e.GetComponent <StateComponent> ();

            int i = AiToInput.GetAbilityCount(e, M_LinkedType);
            //检测是否按下攻击键

            if (i >= ab.m_temporaryAbility.Count || i != input.currentKey)
            {
                continue;
            }

            //若无攻击对象则获取周围可攻击对象
            if (attack.enemy == null)
            {
                attack.enemy = GetEnemyAround(e);
                if (attack.enemy == null)
                {
                    return;
                }
            }
            List <Vector3> el = new List <Vector3> ();
            foreach (var enemy in attack.enemy)
            {
                el.Add(enemy.GetComponent <BlockInfoComponent> ().m_logicPosition);
            }
            UISimple ui = GameObject.Find("UI").GetComponent <UISimple> ();
            ui.ShowUI(el, 2);

            //左键攻击
            if (input.leftButtonDown)
            {
                BasicEntity enemy = map.GetBlockByLogicPos(input.currentPos).entity;

                //检测当前选中敌人是否处于攻击范围内
                List <BasicEntity> list = GetEnemyAround(e);
                if (list != null && !list.Contains(enemy))
                {
                    attack.enemy = list;
                    return;
                }
                //扣除敌人HP值
                DeadComponent  dead  = enemy.GetComponent <DeadComponent> ();
                StateComponent state = e.GetComponent <StateComponent> ();
                dead.hp             -= attack.STR;
                state.m_actionPoint -= 1;
                state.Invoke("AnimationEnd", 1);
                state.AnimationStart();
                //播放攻击动画
                //播放敌人受击动画
                //减少AP
            }
        }
    }
Example #4
0
        public static void Cast(this UnitSkillComponent self, string keycode)
        {
            RayUnitComponent ray    = self.GetParent <Unit>().GetComponent <RayUnitComponent>();
            AttackComponent  attack = self.GetParent <Unit>().GetComponent <AttackComponent>();

            self.currentKey = keycode;
            self.keycodeIds.TryGetValue(self.currentKey, out long skid);
            if (skid == 0)
            {
                skid = 41101;
            }
            Skill skill = Game.Scene.GetComponent <SkillComponent>().Get(skid);

            self.curSkillItem = ComponentFactory.CreateWithId <SkillItem>(skid);

            self.curSkillItem.UpdateLevel(10);

            if (ray.target != null)
            {
                attack.target = ray.target;
            }

            if (attack.target != null)
            {
                attack.target.GetComponent <AttackComponent>().TakeDamage(self.curSkillItem);
            }
        }
Example #5
0
 protected virtual void Start()
 {
     _movement = GetComponent <MovementComponent>();
     _attack   = GetComponent <AttackComponent>();
     _movement.ChooseDirection(Camera.main.transform.position - transform.position);
     StartCoroutine(StartAttack());
 }
 void Awake()
 {
     controller = GetComponent<ControllerComponent> ();
     jumper = GetComponent<JumpComponent> ();
     animator = GetComponent<Animator> ();
     attacker = GetComponent<AttackComponent> ();
 }
Example #7
0
    static public void DoAttack(GameObject attacker, GameObject defender, int skillIndex)
    {
        AttackComponent attackerCom = attacker.GetComponent <Basic>().attackCom;

        if (defender == null || (skillIndex >= skillListSize && skillIndex < 0))
        {
            return;
        }

        AttackComponent defenderCom = defender.GetComponent <Basic>().attackCom;

        if (attackerCom.skillListRegistered[skillIndex])
        {
            AttackInfo attackInfo = attackerCom.attackSkillList[skillIndex]();
            attackerCom.attackSkillEffectList[skillIndex]();

            float resist     = defenderCom.GetResistance(attackInfo.attackType);
            float tempDamage = (1.0f - resist) * (float)attackInfo.attackPoint;

            if ((int)(attackInfo.attackType & AttackType.physics) != 0)
            {
                int dfdpoint = defenderCom.GetDefend();
                tempDamage = (tempDamage > dfdpoint) ? tempDamage - dfdpoint : 0;
            }

            //Debug.Log("Damage:" + (int)tempDamage);
            defender.GetComponent <Basic>().ChangeHealth(-(int)tempDamage);
        }
    }
Example #8
0
    /* Performs an action based on the given target and the unit's type */
    public void startPerformingAction(GameObject entity)
    {
        //Attacks another unit
        if (entity.GetComponent <Unit>() != null)
        {
            AttackComponent attack = gameObject.GetComponent <AttackComponent>();
            if (attack != null)
            {
                Debug.Log("ATTACK");
                actionList.Clear();
                actionList.Add(attack.InstantiateAttackComponent(gameObject, entity));
            }
            //Add a new attack action
            // startAttacking(entity);
        }
        //Checks if the entity to perform an action on is a resource
        ResourceObject resourceObject = entity.GetComponentInParent <ResourceObject>();

        if (resourceObject != null)
        {
            HarvestComponent harvest = gameObject.GetComponent <HarvestComponent>();
            //If harvesting is posible, do it
            if (harvest != null)
            {
                //Harvest
                actionList.Clear();
                actionList.Add(harvest.InstantiateHarvestAction(gameObject, resourceObject.gameObject));
            }
            //Other units move there
            else
            {
                stopAndMoveTo(entity.transform.position);
            }
        }
    }
Example #9
0
        public void Render(RenderHelper rh)
        {
            GraphicsDevice   gd       = rh.graphicsDevice;
            ComponentManager cm       = ComponentManager.GetInstance();
            Viewport         viewport = Extensions.GetCurrentViewport(gd);

            foreach (var Entity in cm.GetComponentsOfType <AttackComponent>())
            {
                AttackComponent attackComponent = (AttackComponent)Entity.Value;
                if (attackComponent.AttackCooldown > 0.0f)
                {
                    MoveComponent     moveComponent     = cm.GetComponentForEntity <MoveComponent>(Entity.Key);
                    PositionComponent positionComponent = cm.GetComponentForEntity <PositionComponent>(Entity.Key);
                    if (attackComponent.Type == WeaponType.Sword)
                    {
                        int       range     = attackComponent.AttackCollisionBox.Size.X;
                        Point     hitOffset = new Point((attackComponent.AttackCollisionBox.Width / 2), (attackComponent.AttackCollisionBox.Height / 2));
                        Rectangle hitArea   = new Rectangle(positionComponent.Position.ToPoint() - hitOffset + moveComponent.Direction * new Point(range, range), attackComponent.AttackCollisionBox.Size).WorldToScreen(ref viewport);
                        if (attackComponent.IsAttacking)
                        {
                            rh.DrawFilledRectangle(hitArea, Color.Red, RenderLayer.Foreground1);
                        }
                        else
                        {
                            rh.DrawFilledRectangle(hitArea, Color.Red, RenderLayer.Foreground1);
                        }
                    }
                }
            }
        }
Example #10
0
    private void Start()
    {
        _movementComponent = GetComponent <MovementComponent>();
        _attackComponent   = GetComponent <AttackComponent>();
        _targetFinder      = GetComponent <TargetFinder>();

        findTargetCondition = (newCandidate, selectedTarget) =>
        {
            var transformPos      = Map.Get2DPos(transform.position);
            var candidatePosition = Map.Get2DPos(newCandidate.transform.position);

            var newDistance      = Vector2.Distance(candidatePosition, transformPos);
            var selectedDistance = float.MaxValue;
            if (selectedTarget)
            {
                selectedDistance = Vector2.Distance(Map.Get2DPos(selectedTarget.transform.position), transformPos);
            }

            if (newDistance <= selectedDistance && newDistance <= _movementComponent.DistanceToCurrentTarget)
            {
                if (_movementComponent.TryToGetNavigablePositionFromTarget(newCandidate, out var pos))
                {
                    return(true);
                }
            }
            return(false);
        };
    }
Example #11
0
 void Start()
 {
     altar              = GameObject.Find("Altar");
     target             = altar;
     movementController = GetComponent <EnemyMovementController>();
     attackComponent    = GetComponent <AttackComponent>();
 }
Example #12
0
    void Start()
    {
        moveComponent   = this.GetComponent <PlayerMovement>();
        aimComponent    = this.GetComponent <Crosshair>();
        attackComponent = this.GetComponent <AttackComponent>();
        health          = GetComponent <Health>();
        energy          = GetComponent <Energy>();

        doubleTapTime      = 1f;
        timeSinceLastTap_W = doubleTapTime;
        timeSinceLastTap_S = doubleTapTime;
        timeSinceLastTap_A = doubleTapTime;
        timeSinceLastTap_D = doubleTapTime;

        if (health != null)
        {
            health.OnDeath += OnDeath;
        }

        GameObject managerObject = GameObject.FindGameObjectWithTag("Manager");

        if (managerObject != null)
        {
            gameMenuManager = managerObject.GetComponent <GameMenuManager>();
        }
    }
Example #13
0
    public void Evolve(AttackComponent element)
    {
        List <Unit> unitsToEvolve = new List <Unit>();

        foreach (Unit unit in unitHolder.hashUnits)
        {
            if (unit.TryGetComponent <Warrior>(out Warrior warrior) && unit.team == Team.Player)
            {
                unitsToEvolve.Add(unit);
            }

            if (unitsToEvolve.Count == 2)
            {
                break;
            }
        }

        foreach (Unit unit in unitsToEvolve)
        {
            unit.health.TakeDamage(1000);
        }

        Unit spawnedUnit = Instantiate(Resources.Load("Warrior_empty", typeof(Unit)) as Unit, transform.position, Quaternion.identity);

        Instantiate(element.attackComponentPrefab, spawnedUnit.transform.position, element.attackComponentPrefab.transform.rotation, spawnedUnit.transform);

        SpriteRenderer renderer = spawnedUnit.GetComponentInChildren <SpriteRenderer>();

        renderer.color  = element.color;
        renderer.sprite = element.unitSprite;

        unitHolder.AddUnit(spawnedUnit);
    }
Example #14
0
    private void OnCollisionEnter(Collision collision)
    {
        if (currentCharge >= maxCharge)
        {
            Explode();
            return;
        }

        ParticleSystem ps = sparksPoolManager.Request();

        ps.gameObject.SetActive(true);
        ps.transform.position = collision.contacts[0].point;

        ParticleSystem.Burst burst = new ParticleSystem.Burst();

        float speedPercent = rb.velocity.magnitude / maxVelocity;
        float min          = speedPercent * 50;

        if (!collision.gameObject.CompareTag("Player"))
        {
            ParticleSystem.MinMaxCurve mmCurve = new ParticleSystem.MinMaxCurve(min, 4 * min);
            burst.count          = mmCurve;
            burst.cycleCount     = 1;
            burst.repeatInterval = 0.01f;

            ps.emission.SetBurst(0, burst);
            ps.Play();
        }
        else
        {
            if (rb.velocity.magnitude > 0.1f * maxVelocity)
            {
                ParticleSystem.MinMaxCurve mmCurve = new ParticleSystem.MinMaxCurve(min, 4 * min);
                burst.count          = mmCurve;
                burst.cycleCount     = 1;
                burst.repeatInterval = 0.01f;

                ps.emission.SetBurst(0, burst);
                ps.Play();

                Player p = collision.gameObject.GetComponent <Player>();

                int pos = Random.Range(0, clipsHitBall.Length);
                AudioSource.PlayClipAtPoint(clipsHitBall[pos], Camera.main.transform.position);

                float chargePercent           = currentCharge / maxCharge;
                float requestedExchangeCharge = chargePercent * chargeExchangedOnHitAtMaxVelocity;

                float exchangeCharge = AttackComponent.GetExchangeCharge(
                    requestedExchangeCharge,
                    currentCharge,
                    p.Charge,
                    p.maxCharge);

                p.IncreaseCharge(exchangeCharge);
                SubstractCharge(exchangeCharge);
                p.OnHit();
            }
        }
    }
        /// <summary>
        /// 攻击 CD 计时
        /// </summary>
        /// <param name="self"></param>
        public static void AttackTarget(this AttackComponent self)
        {
            if (self.delTime == 0)
            {
                //普通攻击,相当于施放技能41101,技能等级为0
                SkillItem skillItem = ComponentFactory.CreateWithId <SkillItem>(41101);

                skillItem.UpdateLevel(0);

                skillItem.GetComponent <ChangeType>().CastId = self.GetParent <Unit>().Id;

                skillItem.GetComponent <NumericComponent>().Set(NumericType.CaseBase, 14);

                self.target.GetComponent <AttackComponent>().TakeDamage(skillItem);

                self.startTime = TimeHelper.ClientNowSeconds();
            }

            long timeNow = TimeHelper.ClientNowSeconds();

            self.delTime = timeNow - self.startTime + 1;

            if (self.delTime > (self.attcdTime + 1))
            {
                self.delTime = 0;
            }
        }
Example #16
0
        public override void PlayAction(AbstractCharacter character)
        {
            AttackComponent attackComponent = character.GetComponent <AttackComponent>();

            attackComponent.AttackSquare(target);
            actionEnded?.Invoke(this, null); // Immediately activates action
        }
Example #17
0
 public static void levelUp(int levels, HealthComponent health, AttackComponent attack)
 {
     health.MaxHealth *= healthMultiplier;
     health.CurrentHealth *= healthMultiplier;
     attack.Damage *= damageMultiplier;
     attack.StunTime *= stunTimeMultiplier;
 }
        /// <summary>
        /// 单目标 减伤列队 取出 循环执行
        /// </summary>
        /// <param name="self"></param>
        public static void WhileTakeDamage(this AttackComponent self)
        {
            while (self.TakeDamages.Count > 0)
            {
                SkillItem skillItem = self.TakeDamages.Dequeue();
                Unit      myself    = self.GetParent <Unit>();
                if (!self.attackers.Contains(skillItem.GetComponent <ChangeType>().CastId))
                {
                    self.attackers.Add(skillItem.GetComponent <ChangeType>().CastId);
                }

                NumericComponent numSk = skillItem.GetComponent <NumericComponent>();
                skillItem.Dispose();
                NumericComponent numSelf = myself.GetComponent <NumericComponent>();
                Random           random  = new Random();
                int dom   = random.Next(0, 99);
                int domhp = numSk[NumericType.Case];
                if (dom < 26)
                {
                    numSelf[NumericType.ValuationAdd] -= (domhp * 2);
                }
                else
                {
                    numSelf[NumericType.ValuationAdd] -= domhp;
                }
                Console.WriteLine(" TakeDamage-143-Myself(" + myself.UnitType + ") : " + "-" + domhp + " / " + numSelf[NumericType.Valuation] + " /Count: " + self.TakeDamages.Count);
            }
        }
        /// <summary>
        /// 死亡判断 后结算
        /// </summary>
        /// <param name="unit"></param>
        public static void RemoveUnit(this AttackComponent self)
        {
            Console.WriteLine(" AttackComponentHelper-172- type: " + self.GetParent <Unit>().UnitType + " 删除单元 Unit。");

            ActorLocationSender actorLocationSender = Game.Scene.GetComponent <ActorLocationSenderComponent>().Get(self.GetParent <Unit>().Id);

            actorLocationSender.Send(new Death_Map());
        }
Example #20
0
        public void AttackTest()
        {
            HealthComponent h = new HealthComponent(100);
            AttackComponent a = new AttackComponent(10);

            a.Attack(h);
            Assert.AreEqual(90, h.Health, "Health after attack incorrect");
        }
Example #21
0
    public Attack(GameAction owner, AttackComponent attackCmp, TileBehavior[] targets)
        : base(owner)
    {
        this.Damage  = attackCmp.Damage;
        this.Targets = targets;

        this.TargetsHit = new List <Character>();
    }
Example #22
0
 protected virtual void Start()
 {
     animator = GetComponent <Animator>();
     health   = GetComponent <HealthComponent>();
     attack   = GetComponent <AttackComponent>();
     dodge    = GetComponent <DodgeComponent>();
     move     = GetComponent <MoveComponent>();
 }
Example #23
0
        void Start()
        {
            GameObject      unit   = new GameObject("Unit");
            AttackComponent attack = unit.AddComponent <AttackComponent>();
            MoveComponent   move   = unit.AddComponent <MoveComponent>();

            attack.Attack();
            move.Move();
        }
Example #24
0
 public Unit(HealthComponent health, AttackComponent attack, MovementComponent movement, TargetComponent target, AiComponent ai,
             StatsComponent stats)
 {
     this.health   = health;
     this.attack   = attack;
     this.movement = movement;
     this.target   = target;
     this.ai       = ai;
     this.stats    = stats;
 }
Example #25
0
 public void DoAttack(GameObject defender, int attackOrder)
 {
     if (defender != null)
     {
         //UnityEngine.Debug.Log("attacking " + defender);
         //UnityEngine.Debug.Log("attacking frame: " + frame);
         AttackComponent.DoAttack(gameObject, defender, attackOrder);
         //AttackComponent.DoCounter(gameObject, defender);
     }
 }
 public static bool CanAttack(
     AttackComponent unitAttackComponent,
     MovementComponent unitMovementComponent,
     MovementComponent targetMovementComponent)
 {
     return(unitAttackComponent.LastAttackTime + unitAttackComponent.AttackDelay <= DateTime.Now &&
            Vector3.Distance(
                unitMovementComponent.CurrentPosition,
                targetMovementComponent.CurrentPosition) <= unitAttackComponent.AttackRange);
 }
 public static bool CanBuildingAttack(AttackComponent unitAttackComponent,
                                      MovementComponent unitMovementComponent,
                                      MovementComponent targetMovementComponent,
                                      int buildScale)
 {
     return(unitAttackComponent.LastAttackTime + unitAttackComponent.AttackDelay <= DateTime.Now &&
            Vector3.Distance(
                unitMovementComponent.CurrentPosition,
                targetMovementComponent.CurrentPosition) <= buildScale);
 }
Example #28
0
        protected override void OnUpdate()
        {
            for (int i = 0; i < AttackTargetEntities.Length; i++)
            {
                Transform             trans           = AttackTargetEntities.Transforms[i];
                AttackTargetComponent attackTarget    = AttackTargetEntities.AttackTargets[i];
                AttackComponent       attackComponent = AttackTargetEntities.AttackComponents[i];

                attackComponent.attackTriggered = Vector3.Distance(trans.position, attackTarget.targetTrans.position) < attackTarget.attackDistance;
            }
        }
Example #29
0
 public EnemyCreature(GameObject _go, Vector2 _position, EnemyProperties _properties) : base(_go, _position)
 {
     properties = _properties;
     Health     = new HealthComponent(this, properties.enemyTroopHealth * UnityEngine.Random.Range(0.9f, 1.1f),
                                      // (1f - properties.enemyTroopHealthVariation, 1f + properties.enemyTroopHealthVariation,)
                                      GameObject.GetComponentInChildren <BloodParticles>());
     Attack = new AttackComponent(properties.enemyDamage * UnityEngine.Random.Range(0.9f, 1.1f),
                                  // (1f - properties.enemyDamageVariation, 1f + properties.enemyDamageeVariation,)
                                  properties.enemyRange, properties.enemyCooldown, animation);
     Speed = new SpeedComponent(properties.enemySpeed * UnityEngine.Random.Range(0.9f, 1.1f), navAgent);
 }
Example #30
0
    void Start()
    {
        ac          = GetComponentInChildren <AttackComponent>();
        rb          = GetComponent <Rigidbody>();
        animator    = GetComponent <Animator>();
        boxCollider = GetComponent <BoxCollider>();

        myTransform = transform;

        currentCharge = baseCharge;
    }
Example #31
0
    private void GetReferences()
    {
        _life     = GetComponent <LifeComponent>();
        _movement = GetComponent <MovementComponent>();
        _attack   = GetComponent <AttackComponent>();

        if (_life == null || _movement == null || _attack == null)
        {
            Debug.LogError($"Missing Controllers for Enemy{gameObject.name}");
        }
    }
Example #32
0
    private void Awake()
    {
        mySeeker          = GetComponent <Seeker>();
        myAttackComponent = GetComponent <AttackComponent>();
        myRigidbody2D     = GetComponent <Rigidbody2D>();

        weaponRenderer.sprite = myAttackComponent.Weapon.ToolSprite;

        myTargets        = new HashSet <GameObject>();
        mySpriteRenderer = GetComponent <SpriteRenderer>();
        myHpComponent    = GetComponent <HpComponent>();
    }
 void Awake()
 {
     body = transform.parent.GetComponent<Rigidbody2D> ();
     attacker = GetComponent<AttackComponent> ();
 }
 public ExperienceComponent(HealthComponent healthComponent, AttackComponent attackComponent)
 {
     this.healthComponent = healthComponent;
     this.attackComponent = attackComponent;
 }
Example #35
0
 void Awake()
 {
     levelComponent = GetComponent<LevelComponent>();
     attackComponent = GetComponent<AttackComponent>();
 }
Example #36
0
 // Use this for initialization
 public void Start()
 {
     Animator animator = GetComponent<Animator>();
     attackComponent = new AttackComponent(animator);
     NavMeshAgent agent = GetComponent<NavMeshAgent>();
     navigationComponent = new NavigationComponent(agent, animator);
     experienceComponent = new ExperienceComponent(healthComponent, attackComponent);
     maxMana = 0;
     currentMana = 0;
     characterName = "Orc";
     className = "Warrior";
     experienceComponent.CurrentLevel = 1;
     experienceComponent.MaxLevel = 1;
     experienceComponent.CurrentExp = 0;
     experienceComponent.MaxExp = 100;
     attackCircle = gameObject.transform.FindChild("AttackCircle").gameObject;
     selectedCircle = gameObject.transform.FindChild("SelectedCircle").gameObject;
     picture = Resources.Load<Sprite>("Icons/orc");
 }
        void Awake()
        {
            agent = GetComponent<NavMeshAgent>();

            GameObject healthBarObject = (GameObject) Instantiate(healthBar, new Vector3(), new Quaternion());
            healthBarObject.transform.SetParent(transform);
            healthBarObject.transform.localPosition = new Vector3(0, 3.0f, 0);
            Image image = healthBarObject.GetComponentInChildren<Image>();
            healthComponent.HealthBar = new HealthBarScript(mainCamera, healthBarObject, image);
            attackComponent = new AttackComponent(animator);
            experienceComponent = new ExperienceComponent(healthComponent, attackComponent);
            navComponent = new NavigationComponent(agent, animator);

            healthComponent.MaxHealth = 100;
            healthComponent.CurrentHealth = 100;
            maxMana = 50;
            currentMana = 50;
            characterName = "Hattori";
            className = "Ninja";
            picture = Resources.Load<Sprite>("Icons/ninjaHead");
            buttons = null;
            selectedCircle = transform.FindChild("SelectedCircle").gameObject;
        }