예제 #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);
    }
예제 #2
0
 private void Awake()
 {
     myAttackComponent = GetComponent <AttackComponent>();
     mySeeker          = GetComponent <Seeker>();
     myTargets         = new HashSet <GameObject>();
     myRigidbody2D     = GetComponent <Rigidbody2D>();
 }
예제 #3
0
    //每帧都会调用对应的实体
    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
            }
        }
    }
예제 #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);
            }
        }
예제 #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> ();
 }
예제 #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);
        }
    }
예제 #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);
            }
        }
    }
예제 #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);
                        }
                    }
                }
            }
        }
예제 #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);
        };
    }
예제 #11
0
 void Start()
 {
     altar              = GameObject.Find("Altar");
     target             = altar;
     movementController = GetComponent <EnemyMovementController>();
     attackComponent    = GetComponent <AttackComponent>();
 }
예제 #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>();
        }
    }
예제 #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);
    }
예제 #14
0
파일: Ball.cs 프로젝트: jaimuepe/Overcharge
    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();
            }
        }
    }
예제 #15
0
        /// <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;
            }
        }
예제 #16
0
        public override void PlayAction(AbstractCharacter character)
        {
            AttackComponent attackComponent = character.GetComponent <AttackComponent>();

            attackComponent.AttackSquare(target);
            actionEnded?.Invoke(this, null); // Immediately activates action
        }
예제 #17
0
 public static void levelUp(int levels, HealthComponent health, AttackComponent attack)
 {
     health.MaxHealth *= healthMultiplier;
     health.CurrentHealth *= healthMultiplier;
     attack.Damage *= damageMultiplier;
     attack.StunTime *= stunTimeMultiplier;
 }
예제 #18
0
        /// <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);
            }
        }
예제 #19
0
        /// <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());
        }
예제 #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");
        }
예제 #21
0
파일: Actions.cs 프로젝트: Zammy/7DRL_2016
    public Attack(GameAction owner, AttackComponent attackCmp, TileBehavior[] targets)
        : base(owner)
    {
        this.Damage  = attackCmp.Damage;
        this.Targets = targets;

        this.TargetsHit = new List <Character>();
    }
예제 #22
0
파일: APawn.cs 프로젝트: navezof/Disarmed
 protected virtual void Start()
 {
     animator = GetComponent <Animator>();
     health   = GetComponent <HealthComponent>();
     attack   = GetComponent <AttackComponent>();
     dodge    = GetComponent <DodgeComponent>();
     move     = GetComponent <MoveComponent>();
 }
예제 #23
0
        void Start()
        {
            GameObject      unit   = new GameObject("Unit");
            AttackComponent attack = unit.AddComponent <AttackComponent>();
            MoveComponent   move   = unit.AddComponent <MoveComponent>();

            attack.Attack();
            move.Move();
        }
예제 #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;
 }
예제 #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);
     }
 }
예제 #26
0
 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);
 }
예제 #27
0
 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);
 }
예제 #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;
            }
        }
예제 #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);
 }
예제 #30
0
    void Start()
    {
        ac          = GetComponentInChildren <AttackComponent>();
        rb          = GetComponent <Rigidbody>();
        animator    = GetComponent <Animator>();
        boxCollider = GetComponent <BoxCollider>();

        myTransform = transform;

        currentCharge = baseCharge;
    }
예제 #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}");
        }
    }
예제 #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> ();
 }
예제 #34
0
 public ExperienceComponent(HealthComponent healthComponent, AttackComponent attackComponent)
 {
     this.healthComponent = healthComponent;
     this.attackComponent = attackComponent;
 }
예제 #35
0
 void Awake()
 {
     levelComponent = GetComponent<LevelComponent>();
     attackComponent = GetComponent<AttackComponent>();
 }
예제 #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");
 }
예제 #37
0
        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;
        }