Beispiel #1
0
    /// <summary>
    /// Casts the ray and does whatever the action is. (Template Method pattern)
    /// </summary>
    /// <returns>
    /// The ray and do.
    /// </returns>
    /// <param name='action'>
    /// If set to <c>true</c> action.
    /// </param>
    public bool CastRayAndDo( OnHit action )
    {
        RaycastHit hit;
        Ray cast = getRayCast();
        int mask = 1 << LayerMask.NameToLayer("Catwalk");
        if ( Physics.Raycast( cast, out hit, CastTestDist, mask ) )
        {
            var blockSpawner = Projectile.GetComponent<BlockSpawner>();

            if ( blockSpawner != null && hit.collider.gameObject.IsProjectile() == false )
            {
                var worldObj = GameObject.FindGameObjectWithTag("World");
                var World = worldObj.GetComponent<GenerateWorld>();
                //var createAt = cast.origin + (cast.direction * (hit.distance - 0.1f));
                var createAt = hit.point + (hit.normal *(0.5f));

                var playerPos = getRayCast().origin;
                var futureIndex = World.getIndexOfPoint( ref createAt);
                var playerIndexTop = World.getIndexOfPoint( ref playerPos);
                var playerIndexBottom = new BlockIndex(playerIndexTop.x, playerIndexTop.y-1, playerIndexTop.z);

                //Don't create on top of ourselves:
                if ( (playerIndexTop != futureIndex) && (playerIndexBottom != futureIndex) )
                {
                    Vector3 currentDirection = getRayCast().direction.normalized;
                    action(World, blockSpawner, hit, currentDirection, createAt, futureIndex);
                }
            }
            return true;
        }
        return false;
    }
Beispiel #2
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        OnHit currentNote = other.GetComponentInParent <OnHit>();

        currentNote.GetKilled();
    }
Beispiel #3
0
 private void NotifyHit(int hitPoints, string objectThatHitName)
 {
     OnHit?.Invoke(hitPoints, objectThatHitName);
 }
Beispiel #4
0
 public static void Hit(int damage)
 {
     OnHit?.Invoke(damage);
 }
Beispiel #5
0
 public override void Register()
 {
     BeforeCast.Add(new CastHandler(ClearSpikeImmunities));
     OnObjectAreaTargetSelect.Add(new ObjectAreaTargetSelectHandler(CountTargets, 0, Targets.UnitDestAreaEnemy));
     OnHit.Add(new HitHandler(SplitDamage));
 }
 public Bullet(int Damage, OnHit OnHit)
 {
     this.Damage      = Damage;
     this.onHitMethod = OnHit;
 }
Beispiel #7
0
 private void Awake()
 {
     _onHit = GetComponentInParent <OnHit>();
 }
Beispiel #8
0
 public void Init(OnHit onHit, GetParentBlock getParentBlock)
 {
     OnHitDelegate          = onHit;
     GetParentBlockDelegate = getParentBlock;
 }
Beispiel #9
0
 public void SetOnHit(OnHit on_hit)
 {
     this.on_hit = on_hit;
 }
Beispiel #10
0
 public void DeregisterOnHit(OnHit effect)
 {
     on_hit_list.Remove(effect);
 }
Beispiel #11
0
 public void RegisterOnHit(OnHit effect)
 {
     on_hit_list.Add(effect);
 }
Beispiel #12
0
 public override void Hit(int damage, int force)
 {
     ApplyDamage(damage + (force / 2));
     OnHit.Raise(this, damage, force);
 }
Beispiel #13
0
 public override void Register()
 {
     OnHit.Add(new HitHandler(InitializeVisualStalker));
 }
Beispiel #14
0
 public void Init(OnHit on_hit)
 {
     this.on_hit = on_hit;
 }
Beispiel #15
0
        private bool Collision(Fixture chara, Fixture obj, Contact list)
        {
            bool returnValue = false;

            if (model.state == CharacterState.attacking &&
                (obj.CollisionCategories != Category.Cat20 || !((MoveModel)obj.Body.UserData).PlayerIndexes.Contains(model.playerIndex)) &&
                currentMove.Stats.Type == MoveType.Body &&
                (currentMove.Stats.StopAtHit || obj.CollisionCategories != Category.Cat11) &&
                currentMove.attackTimeLeft <= currentMove.Stats.Duration - currentMove.Stats.BodyStart)
            {
                moves.EndMove(currentMove);
                moves.RemoveMove(currentMove);
                view.Rotation          = 0;
                view.BoundBox.Rotation = 0;
                model.attackMode       = false;
                if ((obj.CollisionCategories == Category.Cat9 || obj.CollisionCategories == Category.Cat10) && chara.Body.Position.Y + view.size.Y / 2 <= obj.Body.Position.Y - (float)obj.Body.UserData / 2)
                {
                    model.inAir = false;
                    if (obj.CollisionCategories == Category.Cat10)
                    {
                        model.onSoftBox = true;
                    }
                    model.jumpsLeft = 3;
                }

                NaturalState();
                returnValue = true;
            }
            else if ((obj.CollisionCategories == Category.Cat9 || obj.CollisionCategories == Category.Cat10) &&
                     (chara.Body.Position.Y + view.size.Y / 2 <= obj.Body.Position.Y - (float)obj.Body.UserData / 2 && view.VelocityY >= -0.001))
            {
                model.inAir = false;
                if (obj.CollisionCategories == Category.Cat10)
                {
                    model.onSoftBox = true;
                }
                NaturalState();
                model.jumpsLeft = 3;
                returnValue     = true;
            }
            else if (obj.CollisionCategories == Category.Cat9)
            {
                returnValue = true;
            }
            else if (obj.CollisionCategories == Category.Cat20)
            {
                MoveModel move = (MoveModel)obj.Body.UserData;
                if (!move.PlayerIndexes.Contains(model.playerIndex) && !model.invounerable)
                {
                    move.PlayerIndexes.Add(model.playerIndex);

                    MoveStats stats = move.Stats;
                    float     ratio = 0;
                    if (stats.Type == MoveType.Charge && move.chargeTime < stats.MaxWait)
                    {
                        ratio = move.chargeTime / stats.MaxWait;
                    }
                    else
                    {
                        ratio = 1;
                    }
                    Vector2 power  = ratio * stats.Power;
                    int     damage = (int)ratio * stats.Damage;

                    view.Velocity = move.Xdirection * power * (1 + model.damagePoints / 100) * (100 / model.weight);
                    if (Math.Abs(view.VelocityY) == 0)
                    {
                        view.VelocityY = -1;
                    }
                    model.damagePoints += damage;
                    model.setState(CharacterState.takingHit);

                    if (OnHit != null)
                    {
                        OnHit.Invoke(ConvertUnits.ToDisplayUnits(obj.Body.Position), damage, model.damagePoints, move.PlayerIndexes.First(), model.playerIndex, stats.hitSound);
                    }

                    //if (move.Adjustable && ((AdjustableMove)move).StopAtHit) move.attackTimeLeft = 0;
                }
            }
            else if (obj.CollisionCategories == Category.Cat7 || obj.CollisionCategories == Category.Cat8)
            {
                OnCharacterDeath.Invoke(this, obj.CollisionCategories == Category.Cat7);
            }

            return(returnValue);
        }
 protected void RaiseOnHit(AttackPackage attack, AttackResult result)
 {
     OnHit?.Invoke(attack, result);
     _onHit.Invoke();
 }
Beispiel #17
0
 public void AddEventListener(OnHit del)
 {
     _del = del;
 }
Beispiel #18
0
 public void Hit(Hit type, Vector2 direction)
 {
     OnHit?.Invoke(type, direction);
 }
Beispiel #19
0
 public void ClearEventListener()
 {
     _del = null;
 }
Beispiel #20
0
 public void EventHit()
 {
     OnHit?.Invoke();
 }
Beispiel #21
0
 private void OnTriggerEnter2D(Collider2D collider2D)
 {
     OscarRigidbody2D.bodyType = RigidbodyType2D.Static;
     SoundManager.PlaySound(SoundManager.Sound.Whine);
     OnHit?.Invoke(this, EventArgs.Empty);
 }
Beispiel #22
0
 private RayManager()
 {
     onHitDegelate += (obj, hit) => { };
 }
Beispiel #23
0
 private void Hit()
 {
     setPosition(startPosition);
     OnHit.Invoke();
 }
Beispiel #24
0
 public override void Register()
 {
     OnObjectAreaTargetSelect.Add(new ObjectAreaTargetSelectHandler(FilterTargets, 0, Targets.UnitSrcAreaEnemy));
     OnObjectAreaTargetSelect.Add(new ObjectAreaTargetSelectHandler(FilterTargets, 1, Targets.UnitSrcAreaEnemy));
     OnHit.Add(new HitHandler(RecalculateDamage));
 }
Beispiel #25
0
 private void pipeHit()
 {
     OnHit.Invoke();
     setPosition(startPosition);
     transform.position = new Vector3(transform.position.x, pipeY + 0.5f, transform.position.z);
 }
Beispiel #26
0
 private void Weapon_OnHit(IWeapon arg1, Projectile arg2, Collider arg3, Vector3 arg4, Vector3 arg5)
 {
     OnHit?.Invoke(arg1, arg2, arg3, arg4, arg5);
 }
Beispiel #27
0
 public void Hit() => OnHit?.Invoke();
Beispiel #28
0
 public override void Register()
 {
     OnHit.Add(new HitHandler(RecalculateDamage));
 }
Beispiel #29
0
 // Start is called before the first frame update
 void Start()
 {
     gameControllerScript = GameObject.Find("Game Controller").GetComponent <disableAllClicks>();
     onhitScript          = onHitObj.GetComponent <OnHit>();
 }
Beispiel #30
0
 public override void Register()
 {
     OnHit.Add(new HitHandler(HandleOnHit));
 }
 public void GiveDamage(int ammount)
 {
     currentHealth -= ammount;
     OnHit?.Invoke(gameObject.GetComponent <ZombieAI>());
 }