/// <summary>
        /// Checks if the targetfield is a trap
        /// If the target field is a trap it will be triggered and if it is a trapdoor the player will be additionally set to a random free and accessable field
        /// </summary>
        public void TargetFieldIsTrap()
        {
            if (Level.PlayingField[_xPosition, _yPosition].FieldType is Trap)
            {
                Level.PlayingField[_xPosition, _yPosition].FieldType.Effects(SourcePlayer);
                if (Level.PlayingField[_xPosition, _yPosition].FieldType is Trapdoor)
                {
                    Boolean successfulMoving = false;
                    int     randomX;
                    int     randomY;

                    while (successfulMoving == false)
                    {
                        randomX = new Random().Next(0, 19);
                        randomY = new Random().Next(0, 19);

                        if (Level.PlayingField[randomX, randomY].FieldType is Floor && Level.FieldBlockedByPlayer(randomX, randomY) == false)
                        {
                            successfulMoving = true;
                            SourcePlayer.MovePlayer(randomX, randomY);
                        }
                        else
                        {
                            //Player can not move to a wall or another trap
                        }
                    }
                }
            }
            else
            {
                //Field is not a trap
            }
        }
 /// <summary>
 /// Set iscompleted on true, call targetfieldistrap method, call targetfieldcontainsitem method, move the player
 /// and decrement the playerremainingmoves when the sourceplayer has more moves left, the targetfield is valid and the targetfield is in range
 /// </summary>
 public override void Execute()
 {
     if (SourcePlayer.PlayerRemainingMoves < 1)
     {
         throw new CantMoveException("No more moves left");
     }
     else if (TargetFieldIsInvalid() == true)
     {
         throw new CantMoveException("Targetfield is blocked by another player or is a wall");
     }
     else if (VerifyMoveRange() == false)
     {
         throw new CantMoveException("Targetfield is out of range");
     }
     else
     {
         TargetFieldIsTrap();
         TargetFieldContainsItem();
         if (!(Level.PlayingField[XPosition, YPosition].FieldType is Trapdoor))
         {
             SourcePlayer.MovePlayer(XPosition, YPosition);
         }
         SourcePlayer.PlayerRemainingMoves--;
         IsCompleted = true;
     }
 }
Пример #3
0
    public override void Save(GameObject obj)
    {
        SourcePlayer p = obj.GetComponent <SourcePlayer> ();

        if (p == null)
        {
            throw new UnityException("Tried to save a gameobject as a SourcePlayer, but it isn't one!");
        }
        this.pos                 = p.transform.position;
        this.rot                 = p.transform.rotation;
        this.velocity            = p.velocity;
        this.gravity             = p.gravity;
        this.baseFriction        = p.baseFriction;
        this.maxSpeed            = p.maxSpeed;
        this.groundAccelerate    = p.groundAccelerate;
        this.groundDecellerate   = p.groundDecellerate;
        this.airAccelerate       = p.airAccelerate;
        this.airStrafeAccelerate = p.airStrafeAccelerate;
        this.airSpeedBonus       = p.airSpeedBonus;
        this.airSpeedPunish      = p.airSpeedPunish;
        this.airBreak            = p.airBreak;
        this.walkSpeed           = p.walkSpeed;
        this.jumpSpeed           = p.jumpSpeed;
        this.fallSoundThreshold  = p.fallSoundThreshold;
        this.fallPunchThreshold  = p.fallPunchThreshold;
        this.maxSafeFallSpeed    = p.maxSafeFallSpeed;
        this.jumpSpeedBonus      = p.jumpSpeedBonus;
        this.health              = p.health;
        this.mass                = p.mass;

        MouseLook m = obj.GetComponent <MouseLook> ();

        if (m == null)
        {
            throw new UnityException("Tried to save a gameobject as a SourcePlayer, but it isn't one!");
        }
        this.headrotX = m.rotX;
        this.headrotY = m.rotY;

        GunHolder g = obj.GetComponent <GunHolder> ();

        if (g == null)
        {
            throw new UnityException("Tried to save a gameobject as a SourcePlayer, but it isn't one!");
        }
        guns = new GunSaveData[g.Guns.Count];

        int i = 0;

        foreach (GunBase gun in g.Guns)
        {
            guns[i] = new GunSaveData(gun.gameObject);
            i++;
        }
        this.equippedGun = g.Guns.IndexOf(g.EquippedGun);
    }
Пример #4
0
    void OnTriggerEnter(Collider other)
    {
        SourcePlayer p = other.gameObject.GetComponent <SourcePlayer> ();

        if (p != null)
        {
            MouseLook  m          = other.gameObject.GetComponent <MouseLook> ();
            Quaternion difference = Quaternion.Inverse(other.gameObject.transform.rotation) * teleportExit.rotation;
            m.SetRotation(teleportExit.rotation);
            p.velocity = difference * p.velocity;
            other.gameObject.transform.position = teleportExit.position;
            other.gameObject.transform.rotation = teleportExit.rotation;
        }
    }
Пример #5
0
 virtual public void OnEquip(GameObject Player)
 {
     foreach (Collider col in gameObject.GetComponentsInChildren <Collider> ())
     {
         col.enabled = false;
     }
     // It's now part of the player, make sure we don't collide with rockets and the like.
     gameObject.layer = LayerMask.NameToLayer("Player");
     // Switch time
     busy   = switchBusyTime;
     player = Player.GetComponent <SourcePlayer> ();
     view   = Player.GetComponent <MouseLook> ().view;
     gameObject.SetActive(true);
     transform.SetParent(Player.transform);
     transform.position = Player.transform.position + Player.transform.right * .5f - Player.transform.up * .3f;
     transform.rotation = Quaternion.identity;
 }
 /// <summary>
 /// Checks if the targetfield contains a item
 /// If the targetfield contains a visible item it will be collected and deleted from the playingfield
 /// </summary>
 public void TargetFieldContainsItem()
 {
     if (Level.PlayingField[XPosition, YPosition].FieldType is Floor && Level.PlayingField[XPosition, YPosition].Item != null && Level.PlayingField[XPosition, YPosition].Item.IsVisible == true)
     {
         if (SourcePlayer.CollectItem(Level.PlayingField[XPosition, YPosition].Item) == true)
         {
             Level.PlayingField[XPosition, YPosition].Item = null;
         }
         else
         {
             //Player has already a higher level boost
         }
     }
     else
     {
         //Field is not a item
     }
 }
Пример #7
0
    virtual public void OnEquip(GameObject Player)
    {
        foreach (Collider col in gameObject.GetComponentsInChildren <Collider> ())
        {
            col.enabled = false;
        }
        // It's now part of the player, make sure we don't collide with rockets and the like.
        Helper.SetLayerRecursively(gameObject, LayerMask.NameToLayer("Player"));
        // Switch time
        busy      = switchBusyTime;
        player    = Player.GetComponent <SourcePlayer> ();
        view      = Player.GetComponent <MouseLook> ().view;
        childView = Camera.main.GetComponent <Transform>();
        gameObject.SetActive(true);
        Transform shoulderBone = Player.GetComponentInChildren <Animator> ().GetBoneTransform(HumanBodyBones.RightShoulder);

        transform.SetParent(shoulderBone);
        transform.position = shoulderBone.position + shoulderBone.right * 0.4f - shoulderBone.up * 0.1f;
        transform.rotation = Quaternion.identity;
    }
Пример #8
0
    void OnCollisionEnter(Collision other)
    {
        int rand = (int)Random.Range(0, explosions.Count);

        Instantiate(explosions [rand], transform.position, Quaternion.identity); //Quaternion.LookRotation(other.contacts[0].normal));
        Vector3 explosionPos = other.contacts[0].point;

        Destroy(gameObject);
        foreach (Collider hit in Physics.OverlapSphere(explosionPos, radius))
        {
            Rigidbody rb = hit.GetComponent <Rigidbody>();
            if (rb != null)
            {
                rb.AddExplosionForce(power, explosionPos, radius, 3.0F);
            }
            SourcePlayer player = hit.GetComponent <SourcePlayer>();
            if (player != null)
            {
                Vector3 direction = player.transform.position - explosionPos;
                player.velocity += Vector3.Normalize(direction) * power;
            }
        }
    }
Пример #9
0
    public static void RadiusDamage(float damage, float knockBack, Vector3 vecSrcIn, float radius, bool ignoreWorld)
    {
        float   adjustedDamage, falloff;
        Vector3 vecSpot;
        Vector3 vecToTarget;
        Vector3 vecEndPos;

        Vector3 vecSrc = vecSrcIn;

        if (radius != 0f)
        {
            falloff = damage / radius;
        }
        else
        {
            falloff = 1.0f;
        }

        //vecSrc.z += 1;// in case grenade is lying on the ground

        // iterate on all entities in the vicinity.
        List <GameObject> ignoreObjects = new List <GameObject>();

        foreach (Collider other in Physics.OverlapSphere(vecSrc, radius))
        {
            if (other.isTrigger || ignoreObjects.Contains(other.gameObject))
            {
                continue;
            }

            // radius damage can only be blocked by the world
            if (other is CapsuleCollider || other is BoxCollider || other is SphereCollider)
            {
                vecSpot = other.ClosestPoint(vecSrc);
            }
            else
            {
                vecSpot = other.ClosestPointOnBounds(vecSrc);
            }
            ignoreObjects.Add(other.gameObject);

            bool bHit = false;

            if (ignoreWorld)
            {
                vecEndPos = vecSpot;
                bHit      = true;
            }
            else
            {
                RaycastHit hit;
                bool       inSight = Physics.Raycast(vecSrc, Vector3.Normalize(vecSpot - vecSrc), out hit, (vecSpot - vecSrc).magnitude + 0.1f);

                vecEndPos = hit.point;

                if (inSight && hit.collider == other)
                {
                    bHit = true;
                }
            }

            if (bHit)
            {
                // the explosion can 'see' this entity, so hurt them!
                //vecToTarget = ( vecSrc - vecEndPos );
                vecToTarget = (vecEndPos - vecSrc);

                // decrease damage for an ent that's farther from the bomb.
                adjustedDamage = vecToTarget.magnitude * falloff;
                adjustedDamage = damage - adjustedDamage;

                if (adjustedDamage > 0f)
                {
                    Vector3 dir;
                    if (other.GetComponent <SourcePlayer> () == null)
                    {
                        dir = Vector3.Normalize(vecToTarget);
                    }
                    else
                    {
                        // Should base kickback around the players eyes, this doesn't make sense, but it makes it way easier to wall jump with rockets and stuff.
                        dir = Vector3.Normalize(other.transform.position + new Vector3(0f, 0.6f, 0f) - vecSrc);
                    }

                    // Assume the force passed in is the maximum force. Decay it based on falloff.
                    float     flForce = knockBack * falloff;
                    Rigidbody rb      = other.gameObject.GetComponent <Rigidbody>();
                    if (rb != null)
                    {
                        rb.AddForceAtPosition(flForce * dir * 50f, vecEndPos);
                    }
                    SourcePlayer player = other.gameObject.GetComponent <SourcePlayer>();
                    if (player != null)
                    {
                        player.velocity += flForce * dir;
                        player.StunAirBrake(0.25f);
                    }

                    //pEntity->TakeDamage( adjustedInfo );
                }
            }
        }
    }
Пример #10
0
    public override GameObject Load()
    {
        GameObject   obj = GameObject.Instantiate(ResourceManager.GetResource <GameObject>("Player"));
        SourcePlayer ps  = obj.GetComponent <SourcePlayer> ();

        if (!ps)
        {
            throw new UnityException("Tried to load a gameobject as a SourcePlayer, but it isn't one!");
        }
        ps.transform.position  = this.pos;
        ps.transform.rotation  = this.rot;
        ps.velocity            = this.velocity;
        ps.gravity             = this.gravity;
        ps.baseFriction        = this.baseFriction;
        ps.maxSpeed            = this.maxSpeed;
        ps.groundAccelerate    = this.groundAccelerate;
        ps.groundDecellerate   = this.groundDecellerate;
        ps.airAccelerate       = this.airAccelerate;
        ps.airStrafeAccelerate = this.airStrafeAccelerate;
        ps.airSpeedBonus       = this.airSpeedBonus;
        ps.airSpeedPunish      = this.airSpeedPunish;
        ps.airBreak            = this.airBreak;
        ps.walkSpeed           = this.walkSpeed;
        ps.jumpSpeed           = this.jumpSpeed;
        ps.fallSoundThreshold  = this.fallSoundThreshold;
        ps.fallPunchThreshold  = this.fallPunchThreshold;
        ps.maxSafeFallSpeed    = this.maxSafeFallSpeed;
        ps.jumpSpeedBonus      = this.jumpSpeedBonus;
        ps.health = this.health;
        ps.mass   = this.mass;

        MouseLook m = obj.GetComponent <MouseLook> ();

        if (m == null)
        {
            throw new UnityException("Tried to save a gameobject as a SourcePlayer, but it isn't one!");
        }
        m.SetRotation(Quaternion.Euler(this.headrotX, this.headrotY, 0));
        GunHolder g = obj.GetComponent <GunHolder> ();

        if (g == null)
        {
            throw new UnityException("Tried to save a gameobject as a SourcePlayer, but it isn't one!");
        }
        // Recreate all our guns, with the same stats and place them into inventory.
        g.Guns.Clear();
        foreach (GunSaveData gundata in this.guns)
        {
            GameObject gun     = gundata.Load();
            GunBase    realgun = gun.GetComponent <GunBase> ();
            realgun.player   = obj.GetComponent <SourcePlayer>();
            realgun.equipped = false;
            g.Guns.Add(realgun);
        }
        if (this.equippedGun != -1 && this.equippedGun < g.Guns.Count)
        {
            g.EquippedGun = g.Guns [this.equippedGun];
            g.EquippedGun.OnEquip(obj);
            g.EquippedGun.equipped = true;
        }
        // Done!
        return(obj);
    }
Пример #11
0
 void Start()
 {
     body = GetComponent <SourcePlayer> ();
 }
Пример #12
0
 // Use this for initialization
 void Start()
 {
     player = GetComponent <SourcePlayer> ();
 }
Пример #13
0
 public static void SpawnGibs(SourcePlayer player)
 {
 }
Пример #14
0
    public void FitToPlayer(GameObject obj)
    {
        SourcePlayer player = obj.GetComponent <SourcePlayer> ();

        if (player == null)
        {
            Debug.LogError("Tried to fit gibs to unknown object!");
        }
        Animator body = obj.GetComponentInChildren <Animator> ();

        head.transform.position = body.GetBoneTransform(HumanBodyBones.Head).position;
        head.transform.rotation = body.GetBoneTransform(HumanBodyBones.Head).rotation;
        head.GetComponent <Rigidbody> ().velocity = player.velocity;

        chest.transform.position = body.GetBoneTransform(HumanBodyBones.Chest).position;
        chest.transform.rotation = body.GetBoneTransform(HumanBodyBones.Chest).rotation;
        chest.GetComponent <Rigidbody> ().velocity = player.velocity;

        abs.transform.position = body.GetBoneTransform(HumanBodyBones.Hips).position;
        abs.transform.rotation = body.GetBoneTransform(HumanBodyBones.Hips).rotation;
        abs.GetComponent <Rigidbody> ().velocity = player.velocity;

        lleg.transform.position = body.GetBoneTransform(HumanBodyBones.LeftUpperLeg).position;
        lleg.transform.rotation = body.GetBoneTransform(HumanBodyBones.LeftUpperLeg).rotation;
        lleg.GetComponent <Rigidbody> ().velocity = player.velocity;

        rleg.transform.position = body.GetBoneTransform(HumanBodyBones.RightUpperLeg).position;
        rleg.transform.rotation = body.GetBoneTransform(HumanBodyBones.RightUpperLeg).rotation;
        rleg.GetComponent <Rigidbody> ().velocity = player.velocity;

        lfoot.transform.position = body.GetBoneTransform(HumanBodyBones.LeftFoot).position;
        lfoot.transform.rotation = body.GetBoneTransform(HumanBodyBones.LeftFoot).rotation;
        lfoot.GetComponent <Rigidbody> ().velocity = player.velocity;

        rfoot.transform.position = body.GetBoneTransform(HumanBodyBones.RightFoot).position;
        rfoot.transform.rotation = body.GetBoneTransform(HumanBodyBones.RightFoot).rotation;
        rfoot.GetComponent <Rigidbody> ().velocity = player.velocity;

        rfist.transform.position = body.GetBoneTransform(HumanBodyBones.RightHand).position;
        rfist.transform.rotation = body.GetBoneTransform(HumanBodyBones.RightHand).rotation;
        rfist.GetComponent <Rigidbody> ().velocity = player.velocity;

        lfist.transform.position = body.GetBoneTransform(HumanBodyBones.LeftHand).position;
        lfist.transform.rotation = body.GetBoneTransform(HumanBodyBones.LeftHand).rotation;
        lfist.GetComponent <Rigidbody> ().velocity = player.velocity;

        larm.transform.position = body.GetBoneTransform(HumanBodyBones.LeftUpperArm).position;
        larm.transform.rotation = body.GetBoneTransform(HumanBodyBones.LeftUpperArm).rotation;
        larm.GetComponent <Rigidbody> ().velocity = player.velocity;

        rarm.transform.position = body.GetBoneTransform(HumanBodyBones.RightUpperArm).position;
        rarm.transform.rotation = body.GetBoneTransform(HumanBodyBones.RightUpperArm).rotation;
        rarm.GetComponent <Rigidbody> ().velocity = player.velocity;

        rforearm.transform.position = body.GetBoneTransform(HumanBodyBones.RightLowerArm).position;
        rforearm.transform.rotation = body.GetBoneTransform(HumanBodyBones.RightLowerArm).rotation;
        rforearm.GetComponent <Rigidbody> ().velocity = player.velocity;

        lforearm.transform.position = body.GetBoneTransform(HumanBodyBones.LeftLowerArm).position;
        lforearm.transform.rotation = body.GetBoneTransform(HumanBodyBones.LeftLowerArm).rotation;
        lforearm.GetComponent <Rigidbody> ().velocity = player.velocity;
    }