public void Init(Vector3 a_pos, int a_type, bool a_isMine, bool a_isStatic)
 {
     base.transform.position = a_pos;
     m_type     = a_type;
     m_isMine   = a_isMine;
     m_isStatic = a_isStatic;
     if (!a_isStatic)
     {
         GameObject gameObject  = (GameObject)Resources.Load("buildings/building_" + a_type);
         GameObject gameObject2 = null;
         if (null != gameObject)
         {
             gameObject2 = (GameObject)Object.Instantiate(gameObject, base.transform.position, Quaternion.identity);
             gameObject2.transform.parent = base.transform;
             m_animation = gameObject2.transform.Find("Animation");
             ServerBuilding componentInChildren = GetComponentInChildren <ServerBuilding>();
             if (null != componentInChildren)
             {
                 Object.Destroy(componentInChildren);
             }
         }
         else
         {
             gameObject2 = GameObject.CreatePrimitive(PrimitiveType.Sphere);
             gameObject2.transform.position   = base.transform.position;
             gameObject2.transform.localScale = Vector3.one * 0.5f;
             gameObject2.transform.parent     = base.transform;
         }
         m_lastUpdate = Time.time;
     }
     else
     {
         m_animation = base.transform.Find("Animation");
     }
     m_collider = base.collider;
     if (null == m_collider)
     {
         m_collider = GetComponentInChildren <Collider>();
     }
     if (null != base.audio && Time.timeSinceLevelLoad > 5f)
     {
         base.audio.clip = m_buildSound;
         base.audio.Play();
     }
     if (m_type == 102)
     {
         float       time        = Time.time;
         BuildingDef buildingDef = Buildings.GetBuildingDef(102);
         m_explosionTimer = time + ((float)buildingDef.decayTime - 0.3f);
     }
 }
예제 #2
0
    public ServerBuilding GetNearestPlayerBuilding(Vector3 a_pos, int a_ignoreOwnerPid = -1)
    {
        float          num    = 9999999f;
        ServerBuilding result = null;

        for (int i = 0; i < this.m_buildings.Count; i++)
        {
            if (null != this.m_buildings[i] && this.m_buildings[i].GetState() > 0f && this.m_buildings[i].GetOwnerId() != a_ignoreOwnerPid && this.m_buildings[i].GetOwnerId() != 0)
            {
                float sqrMagnitude = (a_pos - this.m_buildings[i].transform.position).sqrMagnitude;
                if (sqrMagnitude < num)
                {
                    result = this.m_buildings[i];
                    num    = sqrMagnitude;
                }
            }
        }
        return(result);
    }
예제 #3
0
    public bool CreateBuilding(int a_type, Vector3 a_pos, int a_ownerPid = 0, float a_yRot = 0f, int a_health = 100, bool a_isNew = true)
    {
        bool flag = false == a_isNew;

        if (!flag)
        {
            ServerBuilding serverBuilding = this.GetNearestPlayerBuilding(a_pos, -1);
            if (null == serverBuilding || (serverBuilding.transform.position - a_pos).sqrMagnitude > 0.20249999f)
            {
                serverBuilding = ((Buildings.IsCollider(a_type) && a_ownerPid != 0) ? this.GetNearestPlayerBuilding(a_pos, a_ownerPid) : null);
                if ((null == serverBuilding || !Buildings.IsDoor(serverBuilding.m_type) || (serverBuilding.transform.position - a_pos).sqrMagnitude > 25f) && (Buildings.IsDoor(a_type) || !Raycaster.BuildingSphereCast(a_pos)) && 0.8f < Util.GetTerrainHeight(a_pos))
                {
                    flag = true;
                }
            }
        }
        if (flag)
        {
            GameObject gameObject = (GameObject)Resources.Load("buildings/building_" + a_type);
            if (null != gameObject)
            {
                GameObject      gameObject2         = (GameObject)UnityEngine.Object.Instantiate(gameObject, a_pos, Quaternion.Euler(0f, a_yRot, 0f));
                ServerBuilding  component           = gameObject2.GetComponent <ServerBuilding>();
                NavMeshObstacle componentInChildren = gameObject2.GetComponentInChildren <NavMeshObstacle>();
                if (null != componentInChildren)
                {
                    componentInChildren.carving = this.m_carveNavMesh;
                }
                if (null != component)
                {
                    component.Init(this.m_server, a_type, a_ownerPid, a_health, a_isNew);
                    this.m_buildings.Add(component);
                }
                else
                {
                    Debug.Log("BuildingManager.cs: ERROR: Building without ServerBuilding.cs script spawned!");
                }
            }
        }
        return(flag);
    }
예제 #4
0
    private void ChangePart(ref Bone a_bone, bool a_optional, int a_newPartType)
    {
        GameObject gameObject = (!a_optional) ? a_bone.lookPart : a_bone.addPart;

        if (null != gameObject)
        {
            Object.Destroy(gameObject);
        }
        if (a_bone == m_boneHand)
        {
            m_handItemExit = null;
            m_handItemType = 0;
            m_handItemDef  = Items.GetItemDef(m_handItemType);
            if (null != m_holoBuilding)
            {
                Object.Destroy(m_holoBuilding);
            }
            m_holoBuilding      = null;
            m_hologramRenderers = null;
        }
        string empty = string.Empty;

        empty = ((a_bone != m_boneHead) ? ("items/item_" + a_newPartType) : ("inventory_steam/go_" + (a_newPartType - 1 + 10000)));
        GameObject gameObject2 = (GameObject)Resources.Load(empty);

        if (null == gameObject2 && !a_optional)
        {
            gameObject2 = ((a_bone != m_boneBody) ? m_headPrefab : m_rucksackPrefab);
        }
        else if (a_optional && a_bone == m_boneBody && !Items.IsBody(a_newPartType))
        {
            gameObject2 = null;
        }
        if (!(null != gameObject2))
        {
            return;
        }
        if (a_optional)
        {
            a_bone.addPart = SetupPart(gameObject2, a_bone.bone, a_optional);
            if (!(null != a_bone.addPart))
            {
                return;
            }
            GetRenderersAndDisableShadows(a_bone.addPart);
            if (a_bone == m_boneHand)
            {
                m_handItemType = a_newPartType;
                m_handItemDef  = Items.GetItemDef(m_handItemType);
                if (m_handItemDef.ammoItemType > 0)
                {
                    m_handItemExit = a_bone.addPart.transform.FindChild("Exit");
                }
                else
                {
                    if (m_handItemDef.buildingIndex <= 0 || !(null != m_input))
                    {
                        return;
                    }
                    GameObject gameObject3 = (GameObject)Resources.Load("buildings/building_" + m_handItemDef.buildingIndex);
                    if (!(null != gameObject3))
                    {
                        return;
                    }
                    m_holoBuilding = SetupPart(gameObject3, base.transform, false);
                    if (null != m_holoBuilding)
                    {
                        ServerBuilding component = m_holoBuilding.GetComponent <ServerBuilding>();
                        if (null != component)
                        {
                            Object.Destroy(component);
                        }
                        m_holoBuilding.transform.localPosition = new Vector3(0f, 0f, 2f);
                        m_holoBuilding.transform.localRotation = Quaternion.Euler(0f, m_input.GetBuildRot(), 0f);
                        m_hologramRenderers = GetRenderersAndDisableShadows(m_holoBuilding);
                    }
                }
            }
            else if (a_bone == m_boneHead)
            {
                a_bone.addPart.transform.localPosition = new Vector3(-0.15f, 0.01f, 0f);
                a_bone.addPart.transform.localRotation = Quaternion.Euler(90f, 270f, 0f);
            }
            else if (a_bone == m_boneBody)
            {
                a_bone.addPart.transform.localPosition = new Vector3(0.104f, 0.018f, 0f);
                a_bone.addPart.transform.localRotation = Quaternion.Euler(90f, 270f, 0f);
            }
        }
        else
        {
            a_bone.lookPart = SetupPart(gameObject2, a_bone.bone, a_optional);
        }
    }
예제 #5
0
    private void CalculateXpAndKarma(Transform a_victim, float a_weaponDamage)
    {
        if (!(null != a_victim) || !(0f < a_weaponDamage))
        {
            return;
        }
        ServerNpc serverNpc = (a_victim.gameObject.layer != 9) ? null : a_victim.GetComponent <ServerNpc>();

        if (null == serverNpc)
        {
            if (a_victim.gameObject.layer == 13)
            {
                ServerPlayer   serverPlayer = null;
                ControlledChar component    = a_victim.GetComponent <ControlledChar>();
                serverPlayer = ((!(null != component)) ? null : component.GetServerPlayer());
                if (serverPlayer == null || serverPlayer.IsSaint())
                {
                    return;
                }
                if (8f < serverPlayer.m_karma)
                {
                    float num = a_weaponDamage * 0.5f * (serverPlayer.m_karma / 200f);
                    if (IsSaint())
                    {
                        num = Mathf.Max(2.5f, num);
                    }
                    ChangeKarmaBy(0f - num);
                }
                else if (IsSaint())
                {
                    ChangeKarmaBy(-2.5f);
                }
            }
            else if (a_victim.gameObject.layer == 19)
            {
                ServerBuilding component2 = a_victim.GetComponent <ServerBuilding>();
                if (null != component2 && m_pid != component2.GetOwnerId() && IsSaint())
                {
                    ChangeKarmaBy(-2.5f);
                }
            }
            else
            {
                if (a_victim.gameObject.layer != 11)
                {
                    return;
                }
                ServerVehicle component3 = a_victim.GetComponent <ServerVehicle>();
                if (null != component3 && 0 < component3.GetPassengerCount())
                {
                    float num2 = a_weaponDamage * 0.25f;
                    if (IsSaint())
                    {
                        num2 = Mathf.Max(2.5f, num2);
                    }
                    ChangeKarmaBy(0f - num2);
                }
            }
            return;
        }
        int   handItem = serverNpc.GetHandItem();
        float num3     = Mathf.Min(serverNpc.GetLastHealth(), a_weaponDamage);
        float num4     = num3 * 0.2f + Items.GetWeaponXpMultiplier(handItem) * (num3 * 0.01f);

        if (!(0f < num4))
        {
            return;
        }
        bool flag = true;

        for (int i = 0; i < m_killXp.Count; i++)
        {
            KillXp killXp = m_killXp[i];
            if (killXp.player == null)
            {
                KillXp killXp2 = m_killXp[i];
                if (serverNpc == killXp2.npc)
                {
                    KillXp value = m_killXp[i];
                    value.xp        += num4;
                    value.deletetime = Time.time + 20f;
                    m_killXp[i]      = value;
                    flag             = false;
                    break;
                }
            }
        }
        if (flag)
        {
            KillXp item = new KillXp(null, serverNpc, num4, Time.time + 20f);
            m_killXp.Add(item);
        }
    }
예제 #6
0
    private void ChangePart(ref Bone a_bone, bool a_optional, int a_newPartType)
    {
        GameObject gameObject = (!a_optional) ? a_bone.lookPart : a_bone.addPart;

        if (null != gameObject)
        {
            UnityEngine.Object.Destroy(gameObject);
        }
        if (a_bone == this.m_boneHand)
        {
            this.m_handItemExit = null;
            this.m_handItemType = 0;
            this.m_handItemDef  = Items.GetItemDef(this.m_handItemType);
            if (null != this.m_holoBuilding)
            {
                UnityEngine.Object.Destroy(this.m_holoBuilding);
            }
            this.m_holoBuilding      = null;
            this.m_hologramRenderers = null;
        }
        string path = string.Empty;

        if (a_bone == this.m_boneHead)
        {
            path = "inventory_steam/go_" + (a_newPartType - 1 + 10000);
        }
        else
        {
            path = "items/item_" + a_newPartType;
        }
        GameObject gameObject2 = (GameObject)Resources.Load(path);

        if (null == gameObject2 && !a_optional)
        {
            gameObject2 = ((a_bone != this.m_boneBody) ? this.m_headPrefab : this.m_rucksackPrefab);
        }
        else if (a_optional && a_bone == this.m_boneBody && !Items.IsBody(a_newPartType))
        {
            gameObject2 = null;
        }
        if (null != gameObject2)
        {
            if (a_optional)
            {
                a_bone.addPart = this.SetupPart(gameObject2, a_bone.bone, a_optional);
                if (null != a_bone.addPart)
                {
                    this.GetRenderersAndDisableShadows(a_bone.addPart);
                    if (a_bone == this.m_boneHand)
                    {
                        this.m_handItemType = a_newPartType;
                        this.m_handItemDef  = Items.GetItemDef(this.m_handItemType);
                        if (this.m_handItemDef.ammoItemType > 0)
                        {
                            this.m_handItemExit = a_bone.addPart.transform.FindChild("Exit");
                        }
                        else if (this.m_handItemDef.buildingIndex > 0 && null != this.m_input)
                        {
                            GameObject gameObject3 = (GameObject)Resources.Load("buildings/building_" + this.m_handItemDef.buildingIndex);
                            if (null != gameObject3)
                            {
                                this.m_holoBuilding = this.SetupPart(gameObject3, base.transform, false);
                                if (null != this.m_holoBuilding)
                                {
                                    ServerBuilding component = this.m_holoBuilding.GetComponent <ServerBuilding>();
                                    if (null != component)
                                    {
                                        UnityEngine.Object.Destroy(component);
                                    }
                                    this.m_holoBuilding.transform.localPosition = new Vector3(0f, 0f, 2f);
                                    this.m_holoBuilding.transform.localRotation = Quaternion.Euler(0f, this.m_input.GetBuildRot(), 0f);
                                    this.m_hologramRenderers = this.GetRenderersAndDisableShadows(this.m_holoBuilding);
                                }
                            }
                        }
                    }
                    else if (a_bone == this.m_boneHead)
                    {
                        a_bone.addPart.transform.localPosition = new Vector3(-0.15f, 0.01f, 0f);
                        a_bone.addPart.transform.localRotation = Quaternion.Euler(90f, 270f, 0f);
                    }
                    else if (a_bone == this.m_boneBody)
                    {
                        a_bone.addPart.transform.localPosition = new Vector3(0.104f, 0.018f, 0f);
                        a_bone.addPart.transform.localRotation = Quaternion.Euler(90f, 270f, 0f);
                    }
                }
            }
            else
            {
                a_bone.lookPart = this.SetupPart(gameObject2, a_bone.bone, a_optional);
            }
        }
    }