/** 获取某ID的第一个物品 */ public override ItemData getItemByID(int id) { IntObjectMap <ItemData> dic = _dicByID.get(id); if (dic == null) { return(null); } if (!dic.isEmpty()) { ItemData[] values; ItemData v; for (int i = (values = dic.getValues()).Length - 1; i >= 0; --i) { if ((v = values[i]) != null) { return(v); } } } return(null); }
/** 设置数据 */ public void setData(IntObjectMap <BuffData> datas) { _buffDataDic = datas; if (datas != null && !datas.isEmpty()) { BuffData[] values = datas.getValues(); BuffData data; for (int i = values.Length - 1; i >= 0; --i) { if ((data = values[i]) != null) { data.config = BuffConfig.get(data.id); data.levelConfig = BuffLevelConfig.get(data.id, data.level); toAddBuffToDic(data); doAddActions(data, _parent.isDriveAll()); } } for (int i = values.Length - 1; i >= 0; --i) { if ((data = values[i]) != null) { data.timeMax = getBuffUseLastTime(data); } } } }
public void setData(IntObjectMap <CDData> cds) { _cds = cds; if (cds != null && !cds.isEmpty()) { IntObjectMap <CDData> groupMaxCDs = _groupMaxCDs; IntIntMap groupCDCount = _groupCDCount; CDData[] values = cds.getValues(); CDData data; for (int i = values.Length - 1; i >= 0; --i) { if ((data = values[i]) != null) { int lastTime = data.getLastTime(); CDConfig config = data.config = CDConfig.get(data.id); foreach (int v in config.groups) { groupCDCount.addValue(v, 1); CDData oldMax = groupMaxCDs.get(v); if (oldMax == null || oldMax.getLastTime() < lastTime) { groupMaxCDs.put(v, data); } } } } } }
/** 添加CD组 */ public void reAddCDs(IntObjectMap <CDData> dic, int dTime) { if (dic.isEmpty()) { return; } IntObjectMap <CDData> cds = _cds; if (!cds.isEmpty()) { Ctrl.throwError("这时cd组不应该有值"); } IntObjectMap <CDData> groupMaxCDs = _groupMaxCDs; IntIntMap groupCDCount = _groupCDCount; UnitFightDataLogic parent = _parent; CDData[] values = dic.getValues(); CDData v; for (int i = values.Length - 1; i >= 0; --i) { if ((v = values[i]) != null) { v.config = CDConfig.get(v.id); v.timePass += dTime; //依然有效 if (v.timePass < v.timeMax) { cds.put(v.id, v); foreach (int gv in v.config.groups) { groupCDCount.addValue(gv, 1); CDData oldMax = groupMaxCDs.get(gv); if (oldMax == null || oldMax.getLastTime() < v.getLastTime()) { groupMaxCDs.put(gv, v); } //新的 if (oldMax == null) { parent.onStartGroupCD(gv); } } } } } _parent.onCDChange(); }
public override void onSecond() { if (!_selfFieldItemBagDic.isEmpty()) { long now = _scene.getTimeMillis(); foreach (FieldItemBagBindData v in _selfFieldItemBagDic) { if (now > v.removeTime) { _selfFieldItemBagDic.remove(v.instanceID); onRemoveFieldItemBagBind(v); } } } }
private void clearRecordDatas() { IntObjectMap <ItemRecordData> itemRecordDic = _itemRecordDic; ObjectPool <ItemRecordData> pool = _recordDataPool; if (!itemRecordDic.isEmpty()) { foreach (ItemRecordData v in itemRecordDic) { if (v.num == 0) { itemRecordDic.remove(v.id); pool.back(v); } } } }
/** 消耗buff次数数组 */ public void subBuffNumArr(int type, int[] arr) { IntObjectMap <BuffData> dic = _buffDatasBySubNums[type]; if (dic == null || dic.isEmpty()) { return; } int bArg; foreach (BuffData v in dic) { bArg = v.config.subNumsDicT[type]; foreach (int t in arr) { //0为任意类型 if (bArg == 0 || bArg == t) { if (v.lastNum > 0) { //没了 if (--v.lastNum == 0) { toRemoveBuff(v); } else { refreshOneBuffAttributeVar(v); } } break; } } } }
/** 消耗buff次数 */ public void subBuffNum(int type, int arg0) { //不是客户端驱动全部 if (!_parent.isDriveAll()) { return; } IntObjectMap <BuffData> dic = _buffDatasBySubNums[type]; if (dic == null || dic.isEmpty()) { return; } int bArg; foreach (BuffData v in dic) { //0为任意类型 if ((bArg = v.config.subNumsDicT[type]) == 0 || bArg == arg0) { if (v.lastNum > 0) { //没了 if (--v.lastNum == 0) { buffOver(v); } else { refreshOneBuffAttributeVar(v); } } } } }
/** 增加当前组CD时间经过(cd减少) */ public void addGroupTimePass(int groupID, int value) { if (value == 0) { return; } if (_cds.isEmpty()) { return; } bool has = false; //只添加,触发还是基于onTen IntIntMap groupCDCount = _groupCDCount; bool needReCount = false; CDData[] values = _cds.getValues(); CDData data; int vv; for (int i = values.Length - 1; i >= 0; --i) { if ((data = values[i]) != null) { if (data.config.hasGroup(groupID)) { has = true; vv = (data.timePass) + value; if (vv > data.timeMax) { vv = data.timeMax; } if (vv < 0) { vv = 0; } data.timePass = vv; if (data.config.groups.Length > 1) { foreach (int gv in data.config.groups) { if (gv != groupID) { //不止这个 if (groupCDCount.get(gv) > 1) { needReCount = true; } } } } } } } if (has) { if (needReCount) { reCountGroupCDMax(); } _parent.onCDChange(); } }
/** 每秒十次 */ public void onPiece(int delay) { if (!_buffDatas.isEmpty()) { //是客户端驱动 if (_parent.isSelfDriveAttackHapen()) { //先触发间隔 if (!_intervalActions.isEmpty()) { AttributeDataLogic attributeLogic = _parent.attribute; foreach (BuffIntervalActionData v in _intervalActions) { v.timePass += delay; if (v.timePass >= v.delay) { v.timePass -= v.delay; switch (v.type) { case BuffIntervalActionType.Attack: { //触发一次 _parent.doBuffIntervalAttack(v); } break; case BuffIntervalActionType.AddAttribute: { if (!_parent.isDriveAll()) { return; } attributeLogic.addOneAttribute(v.key, v.value); } break; case BuffIntervalActionType.AddAttributeVar: { if (!_parent.isDriveAll()) { return; } attributeLogic.addOneAttribute(v.key, _parent.getSkillVarValueT(v.value, v.adderInstanceID)); } break; } } } } } foreach (BuffData data in _buffDatas) { //有持续时间 if (data.lastTime > 0) { if ((data.lastTime -= delay) <= 0) { data.lastTime = 0; //本端驱动才移除 if (_parent.isDriveAll()) { buffOver(data); } } } } } }
/** 重新构造辅助数据 */ private void reMakeData() { IntSet itemTimeSet; if (!_itemRecordDic.isEmpty()) { ItemRecordData[] values; ItemRecordData v; for (int i = (values = _itemRecordDic.getValues()).Length - 1; i >= 0; --i) { if ((v = values[i]) != null) { _recordDataPool.back(v); } } _itemRecordDic.clear(); } (itemTimeSet = _itemTimeSet).clear(); _nextFreeGridIndex = -1; int len = 0; SList <ItemData> list = _list; if (!list.isEmpty()) { int index = list.size() - 1; //先去末尾null while (index >= 0 && list.get(index) == null) { --index; } list.justSetSize(index + 1); ItemData[] values = list.getValues(); ItemData data; len = list.size(); ItemRecordData rData; for (int i = 0; i < len; ++i) { data = values[i]; //空格子 if (data == null) { if (_nextFreeGridIndex == -1) { _nextFreeGridIndex = i; } } else { ++_useGridNum; //构造配置 data.makeConfig(); data.index = i; rData = getRecordDataAbs(data.id); rData.num += data.num; rData.removeIndex = i; //不满 if (!data.isSingleNumMax()) { //没有就添加 if (rData.addIndex != -1) { rData.addIndex = i; } } if (!data.config.enableTimeT.isEmpty()) { itemTimeSet.add(i); } //红点 if (data.hasRedPoint) { _redPointCount++; } } } } if (_gridNum > 0) { if (_gridNum - len > 0) { if (_nextFreeGridIndex == -1) { _nextFreeGridIndex = len; } } } else { if (_nextFreeGridIndex == -1) { _nextFreeGridIndex = len; } } }
/** 结算移除结果 */ protected void flushRemove(int way) { if (_operateRecordList.isEmpty()) { return; } if (_flushing) { Ctrl.throwError("物品操作出现环"); return; } _flushing = true; try { int[] values = _operateRecordList.getValues(); int index; int num; ItemData data; ItemData oldData; //单个 if (_operateRecordList.size() == 2) { data = getItem(index = _operateRecordList.get(0)); num = values[1]; // toSendRemoveOneItem(index,data!=null ? data.num : 0,way); oldData = data != null ? data : _operateRecordRemoveDic.get(index); onItemRemove(index, oldData, num, way); } else { // IntIntMap dic=new IntIntMap(); int len = _operateRecordList.size(); for (int i = 0; i < len; i += 2) { data = getItem(index = values[i]); num = values[i + 1]; // dic.put(index,data!=null ? data.num : 0); oldData = data != null ? data : _operateRecordRemoveDic.get(index); onItemRemove(index, oldData, num, way); } // toSendRemoveItem(dic,way); } _operateRecordList.clear(); if (!_operateRecordRemoveDic.isEmpty()) { ItemData[] values2; ItemData v; for (int i = (values2 = _operateRecordRemoveDic.getValues()).Length - 1; i >= 0; --i) { if ((v = values2[i]) != null) { if (v.canRelease) { releaseItem(v); } } } _operateRecordRemoveDic.clear(); } onChanged(); } catch (Exception e) { Ctrl.errorLog(e); } _flushing = false; }
/// <summary> /// 转文本输出 /// </summary> protected override void toWriteDataString(DataWriter writer) { writer.writeTabs(); writer.sb.Append("funcTools"); writer.sb.Append(':'); writer.sb.Append("Map<int,IntObjectMap<FuncToolData>>"); if (this.funcTools != null) { writer.sb.Append('('); writer.sb.Append(this.funcTools.size()); writer.sb.Append(')'); writer.writeEnter(); writer.writeLeftBrace(); if (!this.funcTools.isEmpty()) { int funcToolsKFreeValue = this.funcTools.getFreeValue(); int[] funcToolsKKeys = this.funcTools.getKeys(); IntObjectMap <FuncToolData>[] funcToolsVValues = this.funcTools.getValues(); for (int funcToolsKI = funcToolsKKeys.Length - 1; funcToolsKI >= 0; --funcToolsKI) { int funcToolsK = funcToolsKKeys[funcToolsKI]; if (funcToolsK != funcToolsKFreeValue) { IntObjectMap <FuncToolData> funcToolsV = funcToolsVValues[funcToolsKI]; writer.writeTabs(); writer.sb.Append(funcToolsK); writer.sb.Append(':'); writer.sb.Append("Map<int,FuncToolData>"); if (funcToolsV != null) { writer.sb.Append('('); writer.sb.Append(funcToolsV.size()); writer.sb.Append(')'); writer.writeEnter(); writer.writeLeftBrace(); if (!funcToolsV.isEmpty()) { int funcToolsVKFreeValue = funcToolsV.getFreeValue(); int[] funcToolsVKKeys = funcToolsV.getKeys(); FuncToolData[] funcToolsVVValues = funcToolsV.getValues(); for (int funcToolsVKI = funcToolsVKKeys.Length - 1; funcToolsVKI >= 0; --funcToolsVKI) { int funcToolsVK = funcToolsVKKeys[funcToolsVKI]; if (funcToolsVK != funcToolsVKFreeValue) { FuncToolData funcToolsVV = funcToolsVVValues[funcToolsVKI]; writer.writeTabs(); writer.sb.Append(funcToolsVK); writer.sb.Append(':'); if (funcToolsVV != null) { funcToolsVV.writeDataString(writer); } else { writer.sb.Append("FuncToolData=null"); } writer.writeEnter(); } } } writer.writeRightBrace(); } else { writer.sb.Append("=null"); } writer.writeEnter(); } } } writer.writeRightBrace(); } else { writer.sb.Append("=null"); } writer.writeEnter(); writer.writeTabs(); writer.sb.Append("funcOpenSet"); writer.sb.Append(':'); writer.sb.Append("Set<int>"); if (this.funcOpenSet != null) { writer.sb.Append('('); writer.sb.Append(this.funcOpenSet.size()); writer.sb.Append(')'); writer.writeEnter(); writer.writeLeftBrace(); if (!this.funcOpenSet.isEmpty()) { int funcOpenSetVFreeValue = this.funcOpenSet.getFreeValue(); int[] funcOpenSetVKeys = this.funcOpenSet.getKeys(); for (int funcOpenSetVI = funcOpenSetVKeys.Length - 1; funcOpenSetVI >= 0; --funcOpenSetVI) { int funcOpenSetV = funcOpenSetVKeys[funcOpenSetVI]; if (funcOpenSetV != funcOpenSetVFreeValue) { writer.writeTabs(); writer.sb.Append(funcOpenSetV); writer.writeEnter(); } } } writer.writeRightBrace(); } else { writer.sb.Append("=null"); } writer.writeEnter(); }
/// <summary> /// 是否数据一致 /// </summary> protected override bool toDataEquals(BaseData data) { FuncPartData mData = (FuncPartData)data; if (mData.funcTools != null) { if (this.funcTools == null) { return(false); } if (this.funcTools.size() != mData.funcTools.size()) { return(false); } IntObjectMap <IntObjectMap <FuncToolData> > funcToolsR = mData.funcTools; if (!this.funcTools.isEmpty()) { int funcToolsKFreeValue = this.funcTools.getFreeValue(); int[] funcToolsKKeys = this.funcTools.getKeys(); IntObjectMap <FuncToolData>[] funcToolsVValues = this.funcTools.getValues(); for (int funcToolsKI = funcToolsKKeys.Length - 1; funcToolsKI >= 0; --funcToolsKI) { int funcToolsK = funcToolsKKeys[funcToolsKI]; if (funcToolsK != funcToolsKFreeValue) { IntObjectMap <FuncToolData> funcToolsV = funcToolsVValues[funcToolsKI]; IntObjectMap <FuncToolData> funcToolsU = funcToolsR.get(funcToolsK); if (funcToolsU != null) { if (funcToolsV == null) { return(false); } if (funcToolsV.size() != funcToolsU.size()) { return(false); } IntObjectMap <FuncToolData> funcToolsVR = funcToolsU; if (!funcToolsV.isEmpty()) { int funcToolsVKFreeValue = funcToolsV.getFreeValue(); int[] funcToolsVKKeys = funcToolsV.getKeys(); FuncToolData[] funcToolsVVValues = funcToolsV.getValues(); for (int funcToolsVKI = funcToolsVKKeys.Length - 1; funcToolsVKI >= 0; --funcToolsVKI) { int funcToolsVK = funcToolsVKKeys[funcToolsVKI]; if (funcToolsVK != funcToolsVKFreeValue) { FuncToolData funcToolsVV = funcToolsVVValues[funcToolsVKI]; FuncToolData funcToolsVU = funcToolsVR.get(funcToolsVK); if (funcToolsVU != null) { if (funcToolsVV == null) { return(false); } if (!funcToolsVV.dataEquals(funcToolsVU)) { return(false); } } else { if (funcToolsVV != null) { return(false); } } } } } } else { if (funcToolsV != null) { return(false); } } } } } } else { if (this.funcTools != null) { return(false); } } if (mData.funcOpenSet != null) { if (this.funcOpenSet == null) { return(false); } if (this.funcOpenSet.size() != mData.funcOpenSet.size()) { return(false); } IntSet funcOpenSetR = mData.funcOpenSet; if (!this.funcOpenSet.isEmpty()) { int funcOpenSetVFreeValue = this.funcOpenSet.getFreeValue(); int[] funcOpenSetVKeys = this.funcOpenSet.getKeys(); for (int funcOpenSetVI = funcOpenSetVKeys.Length - 1; funcOpenSetVI >= 0; --funcOpenSetVI) { int funcOpenSetV = funcOpenSetVKeys[funcOpenSetVI]; if (funcOpenSetV != funcOpenSetVFreeValue) { if (!funcOpenSetR.contains(funcOpenSetV)) { return(false); } } } } } else { if (this.funcOpenSet != null) { return(false); } } return(true); }
/// <summary> /// 写入字节流(完整版) /// </summary> protected override void toWriteBytesFull(BytesWriteStream stream) { stream.startWriteObj(); if (this.funcTools != null) { stream.writeBoolean(true); stream.writeLen(this.funcTools.size()); if (!this.funcTools.isEmpty()) { int funcToolsKFreeValue = this.funcTools.getFreeValue(); int[] funcToolsKKeys = this.funcTools.getKeys(); IntObjectMap <FuncToolData>[] funcToolsVValues = this.funcTools.getValues(); for (int funcToolsKI = funcToolsKKeys.Length - 1; funcToolsKI >= 0; --funcToolsKI) { int funcToolsK = funcToolsKKeys[funcToolsKI]; if (funcToolsK != funcToolsKFreeValue) { IntObjectMap <FuncToolData> funcToolsV = funcToolsVValues[funcToolsKI]; stream.writeInt(funcToolsK); if (funcToolsV != null) { stream.writeBoolean(true); stream.writeLen(funcToolsV.size()); if (!funcToolsV.isEmpty()) { int funcToolsVKFreeValue = funcToolsV.getFreeValue(); int[] funcToolsVKKeys = funcToolsV.getKeys(); FuncToolData[] funcToolsVVValues = funcToolsV.getValues(); for (int funcToolsVKI = funcToolsVKKeys.Length - 1; funcToolsVKI >= 0; --funcToolsVKI) { int funcToolsVK = funcToolsVKKeys[funcToolsVKI]; if (funcToolsVK != funcToolsVKFreeValue) { FuncToolData funcToolsVV = funcToolsVVValues[funcToolsVKI]; stream.writeInt(funcToolsVK); if (funcToolsVV != null) { stream.writeBoolean(true); stream.writeDataFullNotNull(funcToolsVV); } else { stream.writeBoolean(false); } } } } } else { stream.writeBoolean(false); } } } } } else { stream.writeBoolean(false); } if (this.funcOpenSet != null) { stream.writeLen(this.funcOpenSet.size()); if (!this.funcOpenSet.isEmpty()) { int funcOpenSetVFreeValue = this.funcOpenSet.getFreeValue(); int[] funcOpenSetVKeys = this.funcOpenSet.getKeys(); for (int funcOpenSetVI = funcOpenSetVKeys.Length - 1; funcOpenSetVI >= 0; --funcOpenSetVI) { int funcOpenSetV = funcOpenSetVKeys[funcOpenSetVI]; if (funcOpenSetV != funcOpenSetVFreeValue) { stream.writeInt(funcOpenSetV); } } } } else { nullObjError("funcOpenSet"); } stream.endWriteObj(); }
/// <summary> /// 复制(深拷贝) /// </summary> protected override void toCopy(BaseData data) { if (!(data is FuncPartData)) { return; } FuncPartData mData = (FuncPartData)data; if (mData.funcTools != null) { if (this.funcTools != null) { this.funcTools.clear(); this.funcTools.ensureCapacity(mData.funcTools.size()); } else { this.funcTools = new IntObjectMap <IntObjectMap <FuncToolData> >(mData.funcTools.size()); } IntObjectMap <IntObjectMap <FuncToolData> > funcToolsT = this.funcTools; if (!mData.funcTools.isEmpty()) { int funcToolsKFreeValue = mData.funcTools.getFreeValue(); int[] funcToolsKKeys = mData.funcTools.getKeys(); IntObjectMap <FuncToolData>[] funcToolsVValues = mData.funcTools.getValues(); for (int funcToolsKI = funcToolsKKeys.Length - 1; funcToolsKI >= 0; --funcToolsKI) { int funcToolsK = funcToolsKKeys[funcToolsKI]; if (funcToolsK != funcToolsKFreeValue) { IntObjectMap <FuncToolData> funcToolsV = funcToolsVValues[funcToolsKI]; int funcToolsW; IntObjectMap <FuncToolData> funcToolsU; funcToolsW = funcToolsK; if (funcToolsV != null) { funcToolsU = new IntObjectMap <FuncToolData>(funcToolsV.size()); IntObjectMap <FuncToolData> funcToolsUT = funcToolsU; if (!funcToolsV.isEmpty()) { int funcToolsUKFreeValue = funcToolsV.getFreeValue(); int[] funcToolsUKKeys = funcToolsV.getKeys(); FuncToolData[] funcToolsUVValues = funcToolsV.getValues(); for (int funcToolsUKI = funcToolsUKKeys.Length - 1; funcToolsUKI >= 0; --funcToolsUKI) { int funcToolsUK = funcToolsUKKeys[funcToolsUKI]; if (funcToolsUK != funcToolsUKFreeValue) { FuncToolData funcToolsUV = funcToolsUVValues[funcToolsUKI]; int funcToolsUW; FuncToolData funcToolsUU; funcToolsUW = funcToolsUK; if (funcToolsUV != null) { funcToolsUU = (FuncToolData)funcToolsUV.clone(); } else { funcToolsUU = null; } funcToolsUT.put(funcToolsUW, funcToolsUU); } } } } else { funcToolsU = null; } funcToolsT.put(funcToolsW, funcToolsU); } } } } else { this.funcTools = null; } if (mData.funcOpenSet != null) { if (this.funcOpenSet != null) { this.funcOpenSet.clear(); this.funcOpenSet.ensureCapacity(mData.funcOpenSet.size()); } else { this.funcOpenSet = new IntSet(); } IntSet funcOpenSetT = this.funcOpenSet; if (!mData.funcOpenSet.isEmpty()) { int funcOpenSetVFreeValue = mData.funcOpenSet.getFreeValue(); int[] funcOpenSetVKeys = mData.funcOpenSet.getKeys(); for (int funcOpenSetVI = funcOpenSetVKeys.Length - 1; funcOpenSetVI >= 0; --funcOpenSetVI) { int funcOpenSetV = funcOpenSetVKeys[funcOpenSetVI]; if (funcOpenSetV != funcOpenSetVFreeValue) { int funcOpenSetU; funcOpenSetU = funcOpenSetV; funcOpenSetT.add(funcOpenSetU); } } } } else { this.funcOpenSet = null; nullObjError("funcOpenSet"); } }