Beispiel #1
0
    public void AddPasteData(Player player1, MyPreBuildData d)
    {
        //复制一份数据
        var dd = d.GetCopy();

        //加入预建造数据
        AddPrebuildData(player1, dd, out int pid);
        //如果加入成功
        if (pid > 0)
        {
            dd.preId = -pid;
            //加入预建造数据
            preIdMap.Add(pid, dd);
        }
    }
Beispiel #2
0
    /// <summary>
    /// 添加预建筑数据
    /// </summary>
    /// <param name="player">玩家</param>
    /// <param name="d">预建筑</param>
    /// <param name="pId">预建筑id</param>
    /// <param name="IgnoreOverlap">是否忽略重叠</param>
    /// <returns>是否添加成功</returns>
    public int AddPrebuildData(Player player, MyPreBuildData d, out int pId, bool IgnoreOverlap = false)
    {
        pId = -1;
        int id = Common.FindItem(d.ProtoId, planetFactory, player);

        if (id > -1)
        {
            d.SetNewRot(this);
            if (!IgnoreOverlap)
            {
                int posD = d.posSetNum;
                if (posSet.ContainsKey(posD))
                {
                    int eid = posSet[posD];
                    if (player.planetData.factory.entityPool[eid].protoId == d.ProtoId)
                    {
                        d.newEId = eid;

                        if (d.type == EDataType.Inserter)
                        {
                            InserterConnt++;
                            preConnMap.Add(-InserterConnt, d);
                        }
                        else
                        {
                            eIdMap.Add(d.oldEId, eid);
                            preConnMap.Add(d.oldEId, d);
                        }
                    }
                    return(2);
                }
            }
            else
            {
                long pos = GetPosLong(d.pd.pos);
                if (floatPosSet.ContainsKey(pos))
                {
                    int eid = floatPosSet[pos];
                    if (player.planetData.factory.entityPool[eid].protoId == d.ProtoId)
                    {
                        d.newEId = eid;

                        if (d.type == EDataType.Inserter)
                        {
                            InserterConnt++;
                            preConnMap.Add(-InserterConnt, d);
                        }
                        else
                        {
                            eIdMap.Add(d.oldEId, eid);
                            preConnMap.Add(d.oldEId, d);
                        }
                    }
                    if (player.planetData.factory.entityPool[eid].beltId > 0)
                    {
                        BeltEIdMap.Add(d.oldEId, eid);
                    }
                    return(2);
                }
            }
            pId = player.factory.AddPrebuildDataWithComponents(d.pd);
            if (pId > 0)
            {
                //将建筑加入数据,用于撤销
                addBuildData.Add(d);

                d.preId = -pId;
                if (d.type == EDataType.Inserter)
                {
                    InserterConnt++;
                    preConnMap.Add(-InserterConnt, d);
                }
                else
                {
                    preConnMap.Add(d.oldEId, d);
                }
            }

            Common.TakeItem(d.ProtoId, planetFactory, player, id);
            return(1);
        }
        else
        {
            if (d.isBelt)
            {
                playerHaveBeltItem = false;
            }
            if (d.isInserter)
            {
                playerHaveInserterItem = false;
            }
            if ((d.isBelt && !playerHaveBeltItem) || (d.isInserter && !playerHaveInserterItem))
            {
                return(0);
            }
            return(0);
        }
    }
    public void CopyBuildData(PlanetFactory factory, int i)
    {
        var fSystem = factory.factorySystem;
        var ed      = factory.entityPool[i];


        if (ed.protoId > 0)
        {
            if (ed.labId > 0 && ed.storageId > 0 || ed.tankId > 0)
            {
                return;
            }
            MyPreBuildData temp = null;

            if (ed.splitterId > 0)
            {
                var ap = factory.cargoTraffic.splitterPool[ed.splitterId];
                int c0 = factory.entityConnPool[16 * ap.entityId];
                int c1 = factory.entityConnPool[16 * ap.entityId + 1];
                int c2 = factory.entityConnPool[16 * ap.entityId + 2];
                int c3 = factory.entityConnPool[16 * ap.entityId + 3];
                temp = new Splitter(GetPreDate(ed), c0, c1, c2, c3);
            }
            else if (ed.stationId > 0)
            {
                var ap = factory.transport.stationPool[ed.stationId];
                if (ap != null)
                {
                    temp = new Station(GetPreDate(ed), ap);
                }
            }
            else if (ed.inserterId > 0)
            {
                var ip = fSystem.inserterPool[ed.inserterId];
                InserterComponent tempp = ip;
                int outConn             = factory.entityConnPool[i * 16];
                int inConn = factory.entityConnPool[i * 16 + 1];
                temp = new Inserter(GetPreDate(tempp, ed), ip, outConn, inConn);
            }
            else if (ed.beltId > 0)
            {
                var  ap = factory.cargoTraffic.beltPool[ed.beltId];
                bool flag2;
                int  slot;
                factory.ReadObjectConn(i, 0, out flag2, out int out1, out slot);
                factory.ReadObjectConn(i, 1, out flag2, out int in1, out slot);
                factory.ReadObjectConn(i, 2, out flag2, out int in2, out slot);
                factory.ReadObjectConn(i, 3, out flag2, out int in3, out slot);
                temp = new Belt(GetPreDate(ap, ed), ap, out1, in1, in2, in3);
                Belt tBelt = (Belt)temp;
                if (out1 == 0)
                {
                    CheckBeltData.Add(i, tBelt);
                }

                tBelt.beltOut = EIdIsBeltId(out1);
                tBelt.beltIn1 = EIdIsBeltId(in1);
                tBelt.beltIn2 = EIdIsBeltId(in2);
                tBelt.beltIn3 = EIdIsBeltId(in3);
            }
            else if (ed.fractionateId > 0)
            {
                var ap = factory.factorySystem.fractionatePool[ed.fractionateId];
                int c0 = factory.entityConnPool[i * 16];
                int c1 = factory.entityConnPool[i * 16 + 1];
                int c2 = factory.entityConnPool[i * 16 + 2];
                temp = new Fractionate(GetPreDate(ed), c0, c1, c2);
            }
            else if (ed.powerExcId > 0)
            {
                var ap = factory.powerSystem.excPool[ed.powerExcId];
                int c0 = factory.entityConnPool[i * 16];
                int c1 = factory.entityConnPool[i * 16 + 1];
                int c2 = factory.entityConnPool[i * 16 + 2];
                int c3 = factory.entityConnPool[i * 16 + 3];
                temp = new PowerExchanger(GetPreDate(ed), c0, c1, c2, c3, ap.targetState);
            }
            else if (ed.assemblerId > 0)
            {
                var ap = fSystem.assemblerPool[ed.assemblerId];
                temp = new Assembler(GetPreDate(ap, ed));
            }
            else if (ed.ejectorId > 0)
            {
                var ap = fSystem.ejectorPool[ed.ejectorId];
                temp = new Assembler(GetPreDate(ed));
            }
            else if (ed.siloId > 0)
            {
                var ap = fSystem.siloPool[ed.siloId];
                temp = new Assembler(GetPreDate(ed));
            }
            else if (ed.powerGenId > 0)
            {
                var ap = factory.powerSystem.genPool[ed.powerGenId];
                if (ap.gamma)
                {
                    int c0 = factory.entityConnPool[16 * ap.entityId];
                    int c1 = factory.entityConnPool[16 * ap.entityId + 1];
                    temp = new Gamm(GetPreDate(ed), ap.productId, c0, c1);
                }
                else
                {
                    temp      = new Assembler(GetPreDate(ed));
                    temp.type = EDataType.PowGen;
                }
            }
            else if (ed.powerNodeId > 0)
            {
                var ap = factory.powerSystem.nodePool[ed.powerNodeId];
                temp = new Assembler(GetPreDate(ed));
            }
            //else if (ed.storageId > 0)
            //{
            //	var ap = factory.factoryStorage.storagePool[ed.storageId];
            //    if (ap.next == 0)
            //    {
            //		temp = new Assembler(GetPreDate(ed));
            //    }
            //}

            if (temp != null)
            {
                temp.oldEId = i;
                AllData.Add(temp);
                AddItemCount(ed.protoId);
            }
        }
    }