Ejemplo n.º 1
0
    public void ChangeParts(DSignal signal)
    {
        bool _bNext = System.Convert.ToBoolean(signal._arg1);
        int  _step;

        if (_bNext)
        {
            _step = 1;
        }
        else
        {
            _step = -1;
        }
        int _cursor = m_nPartsCursor + _step;

        while (_cursor != m_nPartsCursor)
        {
            if (m_cSlots[_cursor] != null)
            {
                m_nPartsCursor = _cursor;
                return;
            }
            _cursor += _step;
            if (_cursor > 5)
            {
                _cursor = 3;
            }
            if (_cursor < 3)
            {
                _cursor = 5;
            }
        }
    }
Ejemplo n.º 2
0
 public void Damage(DSignal signal)
 {
     m_fHp -= System.Convert.ToSingle(signal._arg1);
     if (m_fHp <= 0.0f)
     {
         Debug.Log(gameObject + " was killed by " + signal._sender);
         Destroy(gameObject);
     }
 }
Ejemplo n.º 3
0
 public void OnReceiveSignal(DSignal signal)
 {
     if (m_ResolverDic.ContainsKey(signal._key))
     {
         SignalResolver _rsvr = m_ResolverDic[signal._key];
         if (_rsvr != null)
         {
             _rsvr(signal);
         }
     }
 }
Ejemplo n.º 4
0
 public static void SendSignal(DSignal signal)
 {
     if (!ms_bIsOnlineMode)
     {
         //single mode, send to the object directly
         signal._receiver.GetComponent <Transceiver>().OnReceiveSignal(signal);
     }
     else
     {
         //online mode, send it to the server
     }
 }
Ejemplo n.º 5
0
    private void OnFireButton(DSignal signal)
    {
        bool _pressed = System.Convert.ToBoolean(signal._arg1);

        if (_pressed)
        {
            Fire();
        }
        else
        {
            CeaseFire();
        }
    }
Ejemplo n.º 6
0
    public void OnDuplicate(DSignal signal)
    {
        Item _item = ((GameObject)signal._arg1).GetComponent <Item>();

        if (_item == null)
        {
            return;
        }
        else
        {
            //copy object references
            _item.OnUse    = OnUse;
            _item.OnUpdate = OnUpdate;
            _item.OnHit    = OnHit;
            _item.m_Cache  = new LuaCache();
        }
    }
Ejemplo n.º 7
0
    private void OnJoystick(DSignal signal)
    {
        float _fHor = System.Convert.ToSingle(signal._arg1);
        float _fVer = System.Convert.ToSingle(signal._arg2);

        if (Mathf.Abs(_fHor) < 1e-4 && Mathf.Abs(_fVer) < 1e-4)
        {
            StopMoving();
        }
        else
        {
            Vector3   _vDirection;
            Transform m_Cam = Camera.main.transform;

            _vDirection = Vector3.Scale(m_Cam.forward, new Vector3(1, 0, 1)).normalized *_fVer + _fHor * m_Cam.right;
            Move(_vDirection);
        }
    }
Ejemplo n.º 8
0
    public void MoveTowards(DSignal signal)
    {
        Vector3 vDirection = (Vector3)signal._arg1;

        //Position
        gameObject.transform.position += vDirection.normalized * m_Properties[SPEED].d_Value * Time.deltaTime;
        //Rotation
        //         Vector3 _vTurn = gameObject.transform.InverseTransformDirection(vDirection);
        //         float _fAngle = Mathf.Atan2(_vTurn.x, _vTurn.z) * Mathf.Rad2Deg;
        //         float _fRotation = 3500.0f * Time.deltaTime;
        //
        //         if (Mathf.Abs(_fAngle) < _fRotation)
        //             _fRotation = _fAngle;
        //         else {
        //             if (_fAngle < 0.0f)
        //                 _fRotation = -_fRotation;
        //         }
        //         gameObject.transform.Rotate(0.0f, _fRotation, 0.0f);
        gameObject.transform.forward = vDirection;
    }
Ejemplo n.º 9
0
    public void onAmmoCreated(DSignal signal)
    {
        Item  _weapon  = GetComponent <Inventory>().GetWeapon();
        Item  _parts   = GetComponent <Inventory>().GetParts();
        float _baseDmg = 0.0f;

        if (_weapon != null)
        {
            _baseDmg += _weapon.m_Damage;
        }

        //temporary, todo
        GameObject _proj = signal._arg1 as GameObject;

        _proj.transform.forward = transform.forward;
        _proj.GetComponent <Projectile>().m_Master  = gameObject;
        _proj.GetComponent <Projectile>().m_Damage += (_baseDmg + transform.GetComponent <Entity>().m_Properties[Entity.RANGE_POWER].d_Value);
        _proj.GetComponent <Projectile>().m_Speed   = 30.0f;
        _proj.GetComponent <Projectile>().m_Weapon  = _weapon;
        _proj.GetComponent <Projectile>().m_Parts   = _parts;
    }
Ejemplo n.º 10
0
    public void Damage(DSignal signal)
    {
        float _fRatio = 100.0f / (100.0f + m_Properties[ARMOR].d_Value);

        if (_fRatio > 10.0f || _fRatio < 0.0f)
        {
            _fRatio = 10.0f;
        }

        float _fDamage = System.Convert.ToSingle(signal._arg1) * _fRatio;

        m_fHp -= _fDamage;
        if (m_fHp <= 0.0f)
        {
            Debug.Log(gameObject + " was killed by " + signal._sender);
            Destroy(gameObject);
            if (gameObject.tag == "Player")//TODO:shouldn't be like this!!!!!!
            {
                Camera.main.GetComponent <GameInput>().m_Player = null;
            }
        }
    }
Ejemplo n.º 11
0
    public void PickUpItem(DSignal signal)
    {
        GameObject itemObject = m_ItemForPick;
        Item       item       = itemObject.GetComponent <Item>();
        bool       _ifFull    = true;

        if (item.m_bPicked)
        {
            //already picked
            m_ItemForPick = null;
            return;
        }
        if (item != null) //check if the object is an Item.
        {
            switch (item.m_Type)
            {
            case ItemType.ITEM_PRIMARY:
                for (int _i = 0; _i < 3; _i++)
                {
                    if (m_cSlots[_i] == null)
                    {
                        m_cSlots[_i] = itemObject;
                        _ifFull      = false;
                        break;
                    }
                }
                if (_ifFull)
                {
                    //full, swap it with the one in hand.
                    MoveBack(m_cSlots[m_nPrimaryCursor], itemObject.transform.position);
                    m_cSlots[m_nPrimaryCursor] = itemObject;
                    //remove bonuses
                    UnEquipItem(m_cSlots[m_nPrimaryCursor]);
                }

                break;

            case ItemType.ITEM_MELEE:

                if (m_cSlots[7] == null)
                {
                    m_cSlots[7] = itemObject;
                }
                else
                {
                    MoveBack(m_cSlots[7], itemObject.transform.position);
                    m_cSlots[7] = itemObject;
                    UnEquipItem(m_cSlots[7]);
                }


                break;

            case ItemType.ITEM_PARTS:
                for (int _i = 3; _i < 6; _i++)
                {
                    if (m_cSlots[_i] == null)
                    {
                        m_cSlots[_i] = itemObject;
                        _ifFull      = false;
                        break;
                    }
                }
                if (_ifFull)
                {
                    //full, swap it with the one in hand.
                    MoveBack(m_cSlots[m_nPartsCursor], itemObject.transform.position);
                    m_cSlots[m_nPartsCursor] = itemObject;
                    //remove bonuses
                    UnEquipItem(m_cSlots[m_nPartsCursor]);
                }

                break;

            case ItemType.ITEM_ARMOR:
                if (m_cSlots[6] == null)
                {
                    m_cSlots[6] = itemObject;
                }
                else
                {
                    MoveBack(m_cSlots[6], itemObject.transform.position);
                    m_cSlots[6] = itemObject;
                    UnEquipItem(m_cSlots[6]);
                }
                break;

            case ItemType.ITEM_SUPPLY:
                break;

            default:
                break;
            }

            //move the itemObject away,todo
            MoveAway(itemObject);

            //apply additional bonuses
            EquipItem(itemObject);
        }
    }
Ejemplo n.º 12
0
    //todo
    public void RangeFire(DSignal signal)
    {
        //merge primary with parts
        GameObject _ammo;

        if (m_cSlots[m_nPrimaryCursor] != null)
        {
            //check cooldown
            if (!m_cSlots[m_nPrimaryCursor].GetComponent <Item>().IfCooled)
            {
                return;
            }
            else
            {
                m_cSlots[m_nPrimaryCursor].GetComponent <Item>().Attack();
            }

            if (m_cSlots[m_nPartsCursor])
            {
                string _ammoName = m_cSlots[m_nPartsCursor].GetComponent <Item>().m_Projectile;
                _ammo = Resources.Load <GameObject>("Prefabs/Projectiles/" + _ammoName);
                if (_ammo == null)
                {
                    Debug.Log("Ammo:Model is null");
                    _ammo = Instantiate(Resources.Load <GameObject>("Prefabs/Projectiles/Default"), /*todo*/ gameObject.transform.position, Quaternion.AngleAxis(0.0f, Vector3.up));
                }
                else
                {
                    _ammo = Instantiate(_ammo, /*todo*/ gameObject.transform.position, Quaternion.AngleAxis(0.0f, Vector3.up));
                }

                _ammo.GetComponent <Projectile>().m_Damage = m_cSlots[m_nPartsCursor].GetComponent <Item>().m_Damage;
            }
            else
            {
                //no ammo, use default
                _ammo = Instantiate(Resources.Load <GameObject>("Prefabs/Projectiles/Default"), /*todo*/ gameObject.transform.position, Quaternion.AngleAxis(0.0f, Vector3.up));
            }

            //temporary, todo
            _ammo.transform.forward = gameObject.transform.forward;
            _ammo.GetComponent <Projectile>().m_Master  = gameObject;
            _ammo.GetComponent <Projectile>().m_Damage += (m_cSlots[m_nPrimaryCursor].GetComponent <Item>().m_Damage + gameObject.GetComponent <EntityAttribute>().m_Properties[EntityAttribute.RANGE_POWER].d_Value);
            _ammo.GetComponent <Projectile>().m_Speed   = 30.0f;

            GameObject _extra;
            switch (m_cSlots[m_nPrimaryCursor].GetComponent <Item>().m_ShotType)
            {
            case ShotType.SHOT_AUTO:
                //no more
                break;

            case ShotType.SHOT_SPREAD:
                //four more
                for (int _i = 0; _i < 6; _i++)
                {
                    _extra = Instantiate(_ammo);
                    _extra.transform.Rotate(0, 20.0f * (Random.value - 0.5f), 0);
                }
                break;

            //undefined
//                 case ShotType.SHOT_ARC:
//                     break;
//                 case ShotType.SHOT_LASER:
//                     break;
            default:
                break;
            }

            _ammo.transform.Rotate(0, 10.0f * (Random.value - 0.5f), 0);
        }
    }