/// <summary> /// 回池 /// </summary> protected override void toRelease(DataPool pool) { this.id = 0; this.cache = null; this.equips = null; this.mIndex = 0; }
/// <summary> /// 复制(深拷贝) /// </summary> protected override void toCopy(BaseData data) { if (!(data is MUnitSaveData)) { return; } MUnitSaveData mData = (MUnitSaveData)data; this.id = mData.id; if (mData.cache != null) { this.cache = (MUnitCacheData)mData.cache.clone(); } else { this.cache = null; } if (mData.equips != null) { this.equips = (EquipContainerData)mData.equips.clone(); } else { this.equips = null; nullObjError("equips"); } this.mIndex = mData.mIndex; }
/// <summary> /// 读取字节流(完整版) /// </summary> protected override void toReadBytesFull(BytesReadStream stream) { stream.startReadObj(); if (stream.readBoolean()) { BaseData heroT = stream.readDataFullNotNull(); if (heroT != null) { if (heroT is MUnitCacheData) { this.hero = (MUnitCacheData)heroT; } else { this.hero = new MUnitCacheData(); if (!(heroT.GetType().IsAssignableFrom(typeof(MUnitCacheData)))) { stream.throwTypeReadError(typeof(MUnitCacheData), heroT.GetType()); } this.hero.shadowCopy(heroT); } } else { this.hero = null; } } else { this.hero = null; } stream.endReadObj(); }
/** 读取缓存 */ public void loadCache(MUnitCacheData data) { if (data != null) { _fightLogic.loadCache(data); } }
/** 读取主城类缓存 */ public void loadTownCache() { if (_townCacheData != null) { _fightLogic.loadCache(_townCacheData); //直接清空 _townCacheData = null; } }
/** 缓存主城类数据 */ public void cacheForTown() { if (_townCacheData == null) { (_townCacheData = new MUnitCacheData()).initDefault(); } _fightLogic.saveCache(_townCacheData, BuffKeepType.InTown); }
/** 缓存到当前数据(见BuffKeepType) */ public void saveCache(MUnitCacheData data, int keepType) { data.cacheTime = getTimeMillis(); //当前属性 IntIntMap currentAttributes = data.currentAttributes; currentAttributes.clear(); int[] currentList = AttributeControl.attribute.currentList; for (int i = currentList.Length - 1; i >= 0; --i) { currentAttributes.put(currentList[i], attribute.getAttribute(currentList[i])); } //buff IntObjectMap <BuffData> buffs = data.buffs; buffs.clear(); BuffData[] values = buff.getBuffDatas().getValues(); BuffData v; for (int i = values.Length - 1; i >= 0; --i) { if ((v = values[i]) != null) { if (v.config.keepType == keepType) { buffs.put(v.instanceID, (BuffData)v.clone()); //clone } } } //cd IntObjectMap <CDData> cds = data.cds; cds.clear(); CDData[] cdValues = cd.getCDs().getValues(); CDData cdV; for (int i = cdValues.Length - 1; i >= 0; --i) { if ((cdV = cdValues[i]) != null) { if (CDConfig.get(cdV.id).keepType == keepType) { cds.put(cdV.id, (CDData)cdV.clone()); //clone } } } }
/// <summary> /// 读取字节流(简版) /// </summary> protected override void toReadBytesSimple(BytesReadStream stream) { if (stream.readBoolean()) { this.hero = (MUnitCacheData)stream.readDataSimpleNotNull(); } else { this.hero = null; } }
/// <summary> /// 复制(潜拷贝) /// </summary> protected override void toShadowCopy(BaseData data) { if (!(data is SceneServerExitData)) { return; } SceneServerExitData mData = (SceneServerExitData)data; this.hero = mData.hero; }
/// <summary> /// 复制(潜拷贝) /// </summary> protected override void toShadowCopy(BaseData data) { if (!(data is MUnitCacheData)) { return; } MUnitCacheData mData = (MUnitCacheData)data; this.currentAttributes = mData.currentAttributes; this.buffs = mData.buffs; this.cds = mData.cds; this.cacheTime = mData.cacheTime; }
/// <summary> /// 复制(潜拷贝) /// </summary> protected override void toShadowCopy(BaseData data) { if (!(data is MUnitSaveData)) { return; } MUnitSaveData mData = (MUnitSaveData)data; this.id = mData.id; this.cache = mData.cache; this.equips = mData.equips; this.mIndex = mData.mIndex; }
/// <summary> /// 读取字节流(简版) /// </summary> protected override void toReadBytesSimple(BytesReadStream stream) { this.id = stream.readInt(); if (stream.readBoolean()) { this.cache = (MUnitCacheData)stream.readDataSimpleNotNull(); } else { this.cache = null; } this.equips = (EquipContainerData)stream.readDataSimpleNotNull(); this.mIndex = stream.readInt(); }
/// <summary> /// 复制(深拷贝) /// </summary> protected override void toCopy(BaseData data) { if (!(data is SceneServerExitData)) { return; } SceneServerExitData mData = (SceneServerExitData)data; if (mData.hero != null) { this.hero = (MUnitCacheData)mData.hero.clone(); } else { this.hero = null; } }
/** 从缓存上读取属性 */ public void loadCache(MUnitCacheData data) { if (data == null) { return; } int dTime = (int)(getTimeMillis() - data.cacheTime); if (!data.buffs.isEmpty()) { foreach (BuffData v in data.buffs) { v.reloadConfig(); //有持续时间 if (v.levelConfig.lastTime > 0) { //超时了 if ((v.lastTime -= dTime) <= 0) { continue; } } buff.addBuffByData(v); } } if (!data.cds.isEmpty()) { cd.reAddCDs(data.cds, dTime); } //最后当前属性 if (!data.currentAttributes.isEmpty()) { data.currentAttributes.forEach((k, v) => { attribute.setOneAttribute(k, v); }); } }
/// <summary> /// 是否数据一致 /// </summary> protected override bool toDataEquals(BaseData data) { MUnitCacheData mData = (MUnitCacheData)data; if (mData.currentAttributes != null) { if (this.currentAttributes == null) { return(false); } if (this.currentAttributes.size() != mData.currentAttributes.size()) { return(false); } IntIntMap currentAttributesR = mData.currentAttributes; if (!this.currentAttributes.isEmpty()) { int currentAttributesKFreeValue = this.currentAttributes.getFreeValue(); int[] currentAttributesKKeys = this.currentAttributes.getKeys(); int[] currentAttributesVValues = this.currentAttributes.getValues(); for (int currentAttributesKI = currentAttributesKKeys.Length - 1; currentAttributesKI >= 0; --currentAttributesKI) { int currentAttributesK = currentAttributesKKeys[currentAttributesKI]; if (currentAttributesK != currentAttributesKFreeValue) { int currentAttributesV = currentAttributesVValues[currentAttributesKI]; int currentAttributesU = currentAttributesR.get(currentAttributesK); if (currentAttributesV != currentAttributesU) { return(false); } } } } } else { if (this.currentAttributes != null) { return(false); } } if (mData.buffs != null) { if (this.buffs == null) { return(false); } if (this.buffs.size() != mData.buffs.size()) { return(false); } IntObjectMap <BuffData> buffsR = mData.buffs; if (!this.buffs.isEmpty()) { int buffsKFreeValue = this.buffs.getFreeValue(); int[] buffsKKeys = this.buffs.getKeys(); BuffData[] buffsVValues = this.buffs.getValues(); for (int buffsKI = buffsKKeys.Length - 1; buffsKI >= 0; --buffsKI) { int buffsK = buffsKKeys[buffsKI]; if (buffsK != buffsKFreeValue) { BuffData buffsV = buffsVValues[buffsKI]; BuffData buffsU = buffsR.get(buffsK); if (buffsU != null) { if (buffsV == null) { return(false); } if (!buffsV.dataEquals(buffsU)) { return(false); } } else { if (buffsV != null) { return(false); } } } } } } else { if (this.buffs != null) { return(false); } } if (mData.cds != null) { if (this.cds == null) { return(false); } if (this.cds.size() != mData.cds.size()) { return(false); } IntObjectMap <CDData> cdsR = mData.cds; if (!this.cds.isEmpty()) { int cdsKFreeValue = this.cds.getFreeValue(); int[] cdsKKeys = this.cds.getKeys(); CDData[] cdsVValues = this.cds.getValues(); for (int cdsKI = cdsKKeys.Length - 1; cdsKI >= 0; --cdsKI) { int cdsK = cdsKKeys[cdsKI]; if (cdsK != cdsKFreeValue) { CDData cdsV = cdsVValues[cdsKI]; CDData cdsU = cdsR.get(cdsK); if (cdsU != null) { if (cdsV == null) { return(false); } if (!cdsV.dataEquals(cdsU)) { return(false); } } else { if (cdsV != null) { return(false); } } } } } } else { if (this.cds != null) { return(false); } } if (this.cacheTime != mData.cacheTime) { return(false); } return(true); }
/// <summary> /// 复制(深拷贝) /// </summary> protected override void toCopy(BaseData data) { if (!(data is MUnitCacheData)) { return; } MUnitCacheData mData = (MUnitCacheData)data; if (mData.currentAttributes != null) { if (this.currentAttributes != null) { this.currentAttributes.clear(); this.currentAttributes.ensureCapacity(mData.currentAttributes.size()); } else { this.currentAttributes = new IntIntMap(mData.currentAttributes.size()); } IntIntMap currentAttributesT = this.currentAttributes; if (!mData.currentAttributes.isEmpty()) { int currentAttributesKFreeValue = mData.currentAttributes.getFreeValue(); int[] currentAttributesKKeys = mData.currentAttributes.getKeys(); int[] currentAttributesVValues = mData.currentAttributes.getValues(); for (int currentAttributesKI = currentAttributesKKeys.Length - 1; currentAttributesKI >= 0; --currentAttributesKI) { int currentAttributesK = currentAttributesKKeys[currentAttributesKI]; if (currentAttributesK != currentAttributesKFreeValue) { int currentAttributesV = currentAttributesVValues[currentAttributesKI]; int currentAttributesW; int currentAttributesU; currentAttributesW = currentAttributesK; currentAttributesU = currentAttributesV; currentAttributesT.put(currentAttributesW, currentAttributesU); } } } } else { this.currentAttributes = null; nullObjError("currentAttributes"); } if (mData.buffs != null) { if (this.buffs != null) { this.buffs.clear(); this.buffs.ensureCapacity(mData.buffs.size()); } else { this.buffs = new IntObjectMap <BuffData>(mData.buffs.size()); } IntObjectMap <BuffData> buffsT = this.buffs; if (!mData.buffs.isEmpty()) { BuffData[] buffsVValues = mData.buffs.getValues(); for (int buffsVI = buffsVValues.Length - 1; buffsVI >= 0; --buffsVI) { BuffData buffsV = buffsVValues[buffsVI]; if (buffsV != null) { BuffData buffsU; if (buffsV != null) { buffsU = (BuffData)buffsV.clone(); } else { buffsU = null; nullObjError("buffsU"); } buffsT.put(buffsU.instanceID, buffsU); } } } } else { this.buffs = null; nullObjError("buffs"); } if (mData.cds != null) { if (this.cds != null) { this.cds.clear(); this.cds.ensureCapacity(mData.cds.size()); } else { this.cds = new IntObjectMap <CDData>(mData.cds.size()); } IntObjectMap <CDData> cdsT = this.cds; if (!mData.cds.isEmpty()) { CDData[] cdsVValues = mData.cds.getValues(); for (int cdsVI = cdsVValues.Length - 1; cdsVI >= 0; --cdsVI) { CDData cdsV = cdsVValues[cdsVI]; if (cdsV != null) { CDData cdsU; if (cdsV != null) { cdsU = (CDData)BytesControl.createData(CDData.dataID); cdsU.copy(cdsV); } else { cdsU = null; nullObjError("cdsU"); } cdsT.put(cdsU.id, cdsU); } } } } else { this.cds = null; nullObjError("cds"); } this.cacheTime = mData.cacheTime; }
/// <summary> /// 回池 /// </summary> protected override void toRelease(DataPool pool) { this.hero = null; }
/// <summary> /// 读取字节流(完整版) /// </summary> protected override void toReadBytesFull(BytesReadStream stream) { stream.startReadObj(); this.id = stream.readInt(); if (stream.readBoolean()) { BaseData cacheT = stream.readDataFullNotNull(); if (cacheT != null) { if (cacheT is MUnitCacheData) { this.cache = (MUnitCacheData)cacheT; } else { this.cache = new MUnitCacheData(); if (!(cacheT.GetType().IsAssignableFrom(typeof(MUnitCacheData)))) { stream.throwTypeReadError(typeof(MUnitCacheData), cacheT.GetType()); } this.cache.shadowCopy(cacheT); } } else { this.cache = null; } } else { this.cache = null; } BaseData equipsT = stream.readDataFullNotNull(); if (equipsT != null) { if (equipsT is EquipContainerData) { this.equips = (EquipContainerData)equipsT; } else { this.equips = new EquipContainerData(); if (!(equipsT.GetType().IsAssignableFrom(typeof(EquipContainerData)))) { stream.throwTypeReadError(typeof(EquipContainerData), equipsT.GetType()); } this.equips.shadowCopy(equipsT); } } else { this.equips = null; } this.mIndex = stream.readInt(); stream.endReadObj(); }