Exemplo n.º 1
0
    void Start()
    {
        // Create colony object if has
        Dictionary <int, CSDefaultData> objRecords = m_DataInst.GetObjectRecords();

        foreach (CSDefaultData defData in objRecords.Values)
        {
            CSObjectData objData = defData as CSObjectData;

            if (objData != null)
            {
                if (!objData.m_Alive)
                {
                    continue;
                }
                CSEntityAttr attr = new CSEntityAttr();
                attr.m_InstanceId = objData.ID;
                attr.m_Type       = objData.dType;
                attr.m_Pos        = objData.m_Position;
                attr.m_protoId    = objData.ItemID;
                CSEntity cse = null;
                CreateEntity(attr, out cse);
            }
        }
    }
Exemplo n.º 2
0
    void Start()
    {
        if (!GameConfig.IsMultiMode)
        {
            m_Type = GetMTypeFromProtoId(itemDrag.itemObj.protoId);
            CSMgCreator creator = CSMain.s_MgCreator;
            if (creator != null)
            {
                CSEntityAttr attr = new CSEntityAttr();
                attr.m_InstanceId = InstanceId;
                attr.m_protoId    = protoId;
                attr.m_Type       = (int)m_Type;
                attr.m_Pos        = transform.position;
                attr.m_LogicObj   = gameObject;
                //attr.m_Bound = GetObjectBounds();
                //attr.m_Bound.center = transform.TransformPoint(attr.m_Bound.center);
                //attr.m_ColonyBase = _ColonyObj;
                int r = creator.CreateEntity(attr, out m_Entity);
                if (r != CSConst.rrtSucceed)
                {
                    Debug.LogError("Error with Init Entities");
                    return;
                }
                _peEntity                    = gameObject.GetComponent <PeEntity>();
                _peTrans                     = gameObject.GetComponent <PeTrans>();
                _skEntity                    = gameObject.GetComponent <PESkEntity>();
                _skEntity.m_Attrs            = new PESkEntity.Attr[5];
                _skEntity.m_Attrs[0]         = new PESkEntity.Attr();
                _skEntity.m_Attrs[1]         = new PESkEntity.Attr();
                _skEntity.m_Attrs[2]         = new PESkEntity.Attr();
                _skEntity.m_Attrs[3]         = new PESkEntity.Attr();
                _skEntity.m_Attrs[4]         = new PESkEntity.Attr();
                _skEntity.m_Attrs[0].m_Type  = AttribType.HpMax;
                _skEntity.m_Attrs[1].m_Type  = AttribType.Hp;
                _skEntity.m_Attrs[2].m_Type  = AttribType.CampID;
                _skEntity.m_Attrs[3].m_Type  = AttribType.DefaultPlayerID;
                _skEntity.m_Attrs[4].m_Type  = AttribType.DamageID;
                _skEntity.m_Attrs[0].m_Value = m_Entity.MaxDurability;
                _skEntity.m_Attrs[1].m_Value = m_Entity.CurrentDurability;
                _skEntity.m_Attrs[2].m_Value = PeCreature.Instance.mainPlayer.GetAttribute(AttribType.CampID);
                _skEntity.m_Attrs[3].m_Value = ForceConstant.PLAYER;
                _skEntity.m_Attrs[4].m_Value = PeCreature.Instance.mainPlayer.GetAttribute(AttribType.DamageID);

                _skEntity.onHpChange += OnHpChange;
                if (m_Type == CSConst.ObjectType.Assembly)
                {
                    _skEntity.onHpChange += SendHpChangeMessage;
                }
                _skEntity.deathEvent += OnDeathEvent;
                _skEntity.InitEntity();
                m_Entity.onDuraChange = SetHp;
                OnHpChange(_skEntity, 0);
                int entityId = Pathea.WorldInfoMgr.Instance.FetchNonRecordAutoId();
                EntityMgr.Instance.InitEntity(entityId, _peEntity.gameObject);
                creator.AddLogic(id, this);
            }
            StartCoroutine(SetFirstConstruct());
        }
    }
Exemplo n.º 3
0
    public CSEntity _createEntity(CSEntityAttr attr)
    {
        // Assembly
        if (attr.m_Type == CSConst.etAssembly)
        {
            m_Assembly            = new CSAssembly();
            m_Assembly.m_Info     = CSInfoMgr.m_AssemblyInfo;
            m_Assembly.ID         = attr.m_InstanceId;
            m_Assembly.gameLogic  = attr.m_LogicObj;
            m_Assembly.gameObject = attr.m_Obj;
            m_Assembly.m_Creator  = this;

            //multiMode only
            m_Assembly._ColonyObj = attr.m_ColonyBase;

            m_Assembly.CreateData();
            m_Assembly.Position     = attr.m_Pos;
            m_Assembly.ItemID       = attr.m_protoId;
            m_Assembly.Bound        = attr.m_Bound;
            m_Assembly.Data.m_Alive = true;
            m_Assembly.InitErodeMap(attr.m_Pos, m_Assembly.Radius);

            m_Timer.Tick = m_Assembly.Data.m_TimeTicks;


            return(m_Assembly);
        }
        else
        {
            CSCommon csc = _CreateCommon(attr.m_Type);

            csc.ID = attr.m_InstanceId;

            //multiMode only
            csc._ColonyObj = attr.m_ColonyBase;

            csc.CreateData();
            csc.Position         = attr.m_Pos;
            csc.m_Power          = attr.m_Power;
            csc.gameLogic        = attr.m_LogicObj;
            csc.gameObject       = attr.m_Obj;
            csc.ItemID           = attr.m_protoId;
            csc.Bound            = attr.m_Bound;
            csc.BaseData.m_Alive = true;

            m_CommonEntities.Add(csc.ID, csc);
            return(csc);
        }
    }
Exemplo n.º 4
0
    // Simulator if need
    //	public CSSimulator m_Simulator;

    public virtual int Init(CSBuildingLogic csbl, CSCreator creator, bool bFight = true)
    {
        this.csbl = csbl;
        CSEntityAttr attr = new CSEntityAttr();

        attr.m_InstanceId   = csbl.InstanceId;
        attr.m_protoId      = csbl.protoId;
        attr.m_Type         = (int)csbl.m_Type;
        attr.m_Pos          = csbl.transform.position;
        attr.m_LogicObj     = csbl.gameObject;
        attr.m_Obj          = gameObject;
        attr.m_Bound        = GetObjectBounds();
        attr.m_Bound.center = transform.TransformPoint(attr.m_Bound.center);
        attr.m_ColonyBase   = _ColonyObj;

        int r;

        r = creator.CreateEntity(attr, out m_Entity);

        if (r != CSConst.rrtSucceed)
        {
            return(r);
        }

        m_Creator  = creator;
        m_ObjectId = csbl.InstanceId;

        // Add ColonyRunner
        if (bFight)
        {
            //--to do: Detectable.cs, if the entity can be attack
//            if (gameObject.GetComponent<ColonyRunner>() == null)
//            {
//                ColonyRunner cr = gameObject.AddComponent<ColonyRunner>();
//                cr.m_Entity = m_Entity;
//            }
        }
        return(r);
    }
Exemplo n.º 5
0
 /// <summary>
 /// Creates the entity, and manage it.
 /// </summary>
 /// <returns>The entity.</returns>
 /// <param name="attr">attribute of the entity</param>
 /// <param name="outEnti">output enti value</param>
 public abstract int CreateEntity(CSEntityAttr attr, out CSEntity outEnti);
Exemplo n.º 6
0
    // <CETC> Create Non-Managed Entity
    public override int CreateEntity(CSEntityAttr attr, out CSEntity outEnti)
    {
        outEnti = null;

        if (attr.m_Type == CSConst.etAssembly)
        {
            Debug.LogWarning("Non-Managed Creator cant create the Assembly Entity.");
            return(CSConst.rrtUnkown);
        }

        if (m_CommonEntities.ContainsKey(attr.m_InstanceId))
        {
            outEnti                  = m_CommonEntities[attr.m_InstanceId];
            outEnti.gameObject       = attr.m_Obj;
            outEnti.Position         = attr.m_Pos;
            outEnti.ItemID           = attr.m_protoId;
            outEnti.BaseData.m_Alive = true;
            return(CSConst.rrtSucceed);
        }

        CSCommon csc = null;

        switch (attr.m_Type)
        {
        case CSConst.etStorage:
            csc = new CSStorage();
            CSStorage css = csc as CSStorage;
            css.m_Info    = CSInfoMgr.m_StorageInfo;
            css.m_Creator = this;
            css.m_Power   = attr.m_Power;
            css.m_Package.ExtendPackage(CSInfoMgr.m_StorageInfo.m_MaxItem, CSInfoMgr.m_StorageInfo.m_MaxEquip, CSInfoMgr.m_StorageInfo.m_MaxRecource, CSInfoMgr.m_StorageInfo.m_MaxArmor);
            break;

        case CSConst.etEnhance:
            csc = new CSEnhance();
            CSEnhance csen = csc as CSEnhance;
            csen.m_Creator = this;
            csen.m_Power   = attr.m_Power;
            csen.m_Info    = CSInfoMgr.m_EnhanceInfo;
            break;

        case CSConst.etRepair:
            csc = new CSRepair();
            CSRepair csr = csc as CSRepair;
            csr.m_Creator = this;
            csr.m_Power   = attr.m_Power;
            csr.m_Info    = CSInfoMgr.m_RepairInfo;
            break;

        case CSConst.etRecyle:
            csc = new CSRecycle();
            CSRecycle csrc = csc as CSRecycle;
            csrc.m_Creator = this;
            csrc.m_Power   = attr.m_Power;
            csrc.m_Info    = CSInfoMgr.m_RecycleInfo;
            break;

        case CSConst.etDwelling:
            csc = new CSDwellings();
            CSDwellings csd = csc as CSDwellings;
            csd.m_Creator = this;
            csd.m_Power   = attr.m_Power;;
            csd.m_Info    = CSInfoMgr.m_DwellingsInfo;
            break;

        case CSConst.etppCoal:
            csc = new CSPPCoal();
            CSPPCoal cscppc = csc as CSPPCoal;
            cscppc.m_Creator   = this;
            cscppc.m_Power     = 10000;
            cscppc.m_RestPower = 10000;
            cscppc.m_Info      = CSInfoMgr.m_ppCoal;
            break;

        case CSConst.etppSolar:
            csc = new CSPPSolar();
            CSPPSolar cspps = csc as CSPPSolar;
            cspps.m_Creator   = this;
            cspps.m_Power     = 10000;
            cspps.m_RestPower = 10000;
            cspps.m_Info      = CSInfoMgr.m_ppCoal;
            break;

        case CSConst.etFactory:
            csc           = new CSFactory();
            csc.m_Creator = this;
            csc.m_Info    = CSInfoMgr.m_FactoryInfo;
            break;

        default:
            break;
        }

        csc.ID = attr.m_InstanceId;
        csc.CreateData();
        csc.gameObject = attr.m_Obj;
        csc.Position   = attr.m_Pos;
        csc.ItemID     = attr.m_protoId;

        outEnti = csc;
        m_CommonEntities.Add(attr.m_InstanceId, csc);
        return(CSConst.rrtSucceed);
    }
Exemplo n.º 7
0
    public void AddDataToCreator(ColonyNetwork colonyNetwork, int teamNum)
    {
        CSMgCreator creator;

        if (teamNum == BaseNetwork.MainPlayer.TeamId)
        {
            creator = CSMain.s_MgCreator;
        }
        else
        {
            creator = CSMain.Instance.MultiGetOtherCreator(teamNum) as CSMgCreator;
        }
        creator.teamNum = teamNum;
        CSObjectData objData = colonyNetwork._ColonyObj._RecordData as CSObjectData;

        if (objData != null
            //&& objData.ID != CSConst.etID_Farm//--to do:?
            )
        {
            //if (!objData.m_Alive)
            //    return;

            CSEntityAttr attr = new CSEntityAttr();
            attr.m_InstanceId = objData.ID;
            attr.m_Type       = objData.dType;
            attr.m_Pos        = objData.m_Position;
            attr.m_protoId    = objData.ItemID;
            attr.m_Bound      = objData.m_Bounds;
            attr.m_ColonyBase = colonyNetwork._ColonyObj;
            CSEntity cse = creator._createEntity(attr);
            colonyNetwork.m_Entity = cse;

            if (objData.dType == CSConst.dtAssembly)
            {
                CSAssembly csa = cse as CSAssembly;
                csa.ChangeState();
            }
            else
            {
                CSCommon csc = cse as CSCommon;
                if (creator.Assembly != null)
                {
                    creator.Assembly.AttachCommonEntity(csc);
                }


                if (cse as CSDwellings != null)
                {
                    cse._Net.RPCServer(EPacketType.PT_CL_DWL_SyncNpc);
                }

                foreach (CSPersonnel csp in creator.GetNpcs())
                {
                    if (csp.Data.m_WorkRoomID == attr.m_InstanceId && csp.WorkRoom != csc)
                    {
                        csp.WorkRoom = csc;
                    }
                }
            }
            //init worker



            creator.ExecuteEvent(CSConst.cetAddEntity, cse);
        }
    }
Exemplo n.º 8
0
    // Use this for initialization
    void Start()
    {
        if (!GameConfig.IsMultiMode)
        {
            // Create Simulator object
//			GameObject go = new GameObject("Simulator Mgr");
//			m_SimulatorMgr = go.gameObject.AddComponent<CSSimulatorMgr>();
//			m_SimulatorMgr.transform.parent = transform;
//			m_SimulatorMgr.Init(ID);


            // Create colony object if has
            Dictionary <int, CSDefaultData> objRecords = m_DataInst.GetObjectRecords();
            foreach (CSDefaultData defData in objRecords.Values)
            {
                CSObjectData objData = defData as CSObjectData;

                if (objData != null && objData.ID != CSConst.etID_Farm)
                {
                    if (!objData.m_Alive)
                    {
                        continue;
                    }

                    CSEntityAttr attr = new CSEntityAttr();
                    attr.m_InstanceId = objData.ID;
                    attr.m_Type       = objData.dType;
                    attr.m_Pos        = objData.m_Position;
                    attr.m_protoId    = objData.ItemID;
                    attr.m_Bound      = objData.m_Bounds;
                    CSEntity cse = _createEntity(attr);

                    if (objData.dType == CSConst.dtAssembly)
                    {
                        CSAssembly csa = cse as CSAssembly;
                        csa.ChangeState();
                    }
                    else
                    {
                        CSCommon csc = cse as CSCommon;
                        if (m_Assembly != null)
                        {
                            m_Assembly.AttachCommonEntity(csc);
                        }
                    }

                    // Create Simulator First
//					CSSimulator sim = null;
//					bool isNew = m_SimulatorMgr.CreateSimulator(objData.ID, out sim);
//					if (isNew)
//					{
//						CSSimulatorAttr cssAttr = new CSSimulatorAttr();
//						cssAttr.m_Hp = cse.m_Info.m_Durability / 0.6f;
//
//						sim.Init(cssAttr);
//					}
//
//					sim.Hp = sim.MaxHp * cse.DuraPercent;
//					sim.Position = cse.Position;
//					sim.noticeHpChanged = cse.OnLifeChanged;
                }
            }

            //delay load colony npc
            StartCoroutine(InitColonyNpc());
        }
        else
        {
            Debug.Log("<color=red>Creator start! Desc:" + gameObject.name + "</color>");
        }
    }
Exemplo n.º 9
0
    //
//	private CSSimulatorMgr m_SimulatorMgr;
//	public CSSimulatorMgr  SimulatorMgr     { get { return m_SimulatorMgr;} }

    // <CETC> Create Managed Entity
    public override int CreateEntity(CSEntityAttr attr, out CSEntity outEnti)
    {
        outEnti = null;
        if (attr.m_Type == CSConst.etAssembly)
        {
            Vector3 travelPos = Vector3.zero;

            CSBuildingLogic csb = attr.m_LogicObj == null ? null : attr.m_LogicObj.GetComponent <CSBuildingLogic>();
            //lz-2017.01.17 基地逻辑预制物体加载成功并且有传送点就用配置的传送点的位置
            if (csb != null && csb.travelTrans != null)
            {
                travelPos = csb.travelTrans.position;
            }
            //lz-2017.01.17 否则就用基地核心向上偏移两米的位置
            else
            {
                travelPos = m_Assembly.Position + new Vector3(0, 2, 0);
            }

            if (m_Assembly == null)
            {
                if (GameConfig.IsMultiMode && attr.m_ColonyBase == null)
                {
                    return(CSConst.rrtUnkown);
                }
                outEnti = _createEntity(attr);
                m_Assembly.ChangeState();

                if (CSMain.s_MgCreator == this)
                {
                    ColonyLabel.Remove(travelPos);
                    new ColonyLabel(travelPos);
                }
            }
            else if (m_Assembly.ID == attr.m_InstanceId)
            {
                outEnti                 = m_Assembly;
                outEnti.gameLogic       = attr.m_LogicObj;
                outEnti.gameObject      = attr.m_Obj;
                outEnti.Position        = attr.m_Pos;
                outEnti.ItemID          = attr.m_protoId;
                outEnti.Bound           = attr.m_Bound;
                m_Assembly.Data.m_Alive = true;
                if (CSMain.s_MgCreator == this)
                {
                    ColonyLabel.Remove(travelPos);
                    new ColonyLabel(travelPos);
                }
            }
            else
            {
                if (m_Assembly != null)
                {
                    return(CSConst.rrtHasAssembly);
                }
            }
        }
        else
        {
            if (m_CommonEntities.ContainsKey(attr.m_InstanceId))
            {
                outEnti                  = m_CommonEntities[attr.m_InstanceId];
                outEnti.gameLogic        = attr.m_LogicObj;
                outEnti.gameObject       = attr.m_Obj;
                outEnti.Position         = attr.m_Pos;
                outEnti.ItemID           = attr.m_protoId;
                outEnti.BaseData.m_Alive = true;
                outEnti.Bound            = attr.m_Bound;
            }
            else
            {
                if (m_Assembly == null)
                {
                    return(CSConst.rrtNoAssembly);
                }

                if (!m_Assembly.InRange(attr.m_Pos))
                {
                    return(CSConst.rrtOutOfRadius);
                }

                // Is powerplant ?
                CSConst.ObjectType obj_type;
//                if ((attr.m_Type & CSConst.etPowerPlant) != 0)
//                    obj_type = CSConst.ObjectType.PowerPlant;
//                else
                obj_type = (CSConst.ObjectType)attr.m_Type;

                if (!m_Assembly.OutOfCount(obj_type))
                {
                    return(CSConst.rrtOutOfRange);
                }

                if (GameConfig.IsMultiMode && attr.m_ColonyBase == null)
                {
                    return(CSConst.rrtUnkown);
                }
                outEnti = _createEntity(attr);
                CSCommon csc = outEnti as CSCommon;
                m_Assembly.AttachCommonEntity(csc);
            }
        }
        ExecuteEvent(CSConst.cetAddEntity, outEnti);
        return(CSConst.rrtSucceed);
    }