protected override void OnRequest(request_bap_fittings request, object userdata) { BapFittingsActionParam param = userdata as BapFittingsActionParam; if (param == null) { return; } request.pos = param.pos; request.price = param.price; request.itemId = param.itemId; for (int i = 0; i < (int)FittingsType.MAX_PROPERTY; ++i) { request.mproperty.Add(param.get_mproperty(i)); request.mvalue.Add(param.get_mvalue(i)); request.mlock.Add(param.get_mlock(i)); request.start.Add(param.get_start(i)); request.end.Add(param.get_end(i)); } }
public void BapFittings(uint pos, int fiId, bool[] lockIndex) { PlayerDataModule module = ModuleManager.Instance.FindModule <PlayerDataModule>(); if (module == null) { return; } FittingsData fdata = module.GetFittingsData(pos); if (fdata == null) { return; } int id = fdata.GetId(); FittingsTableItem fres = DataManager.FittingsTable[id] as FittingsTableItem; if (fres == null) { return; } uint chance = module.GetFittChance(); BapFittingsActionParam param = new BapFittingsActionParam(); param.pos = pos; param.itemId = (uint)fres.costid; if (chance <= 0) { int lnum = 0; for (int i = 0; i < (int)FittingsType.MAX_PROPERTY; ++i) { if (lockIndex[i]) { lnum++; } } uint cnum = 0; if (lnum == 0) { cnum = fres.num_0; } else if (lnum == 1) { cnum = fres.num_1; } else if (lnum == 2) { cnum = fres.num_2; } uint count = PlayerDataPool.Instance.MainData.mPack.GetNumByID(fres.costid); if (count < cnum) { string ons = ItemManager.Instance.getItemName(fres.costid); PopTipManager.Instance.AddNewTip(StringHelper.GetString("item_need").Replace("?", ons)); return; } param.price = cnum; } else { param.price = 0; } int mCount = 0; for (int i = 0; i < (int)FittingsType.MAX_PROPERTY; ++i) { int proid = -1; if (lockIndex[mCount]) { int value = -1; bool forbid = false; if (!fdata.GetProValue((uint)mCount, ref proid, ref value, ref forbid)) { continue; } param.set_mproperty(mCount, proid); param.set_mvalue(mCount, value); param.set_mlock(mCount, lockIndex[mCount]); param.set_start(mCount, (uint)0); param.set_end(mCount, (uint)1); mCount++; continue; } proid = fres.GetProId(); if (proid == -1) { continue; } int ind = FittingsProperty.GetResId(proid); int minid = 0; int maxid = 0; if (!fres.GetIntervalByID(ind, ref minid, ref maxid)) { continue; } FittoddsTableItem odres = DataManager.FittoddsTable[maxid] as FittoddsTableItem; if (odres == null) { GameDebug.LogError("fittodds.txt填写错误 id = " + maxid); return; } uint roodds = (uint)UnityEngine.Random.Range(0, (int)odres.odds); for (int j = minid; j <= maxid; ++j) { FittoddsTableItem rares = DataManager.FittoddsTable[j] as FittoddsTableItem; if (rares == null) { GameDebug.LogError("fittodds.txt填写错误 id = " + j); return; } if (rares.odds > roodds) { param.set_mproperty(mCount, proid); param.set_mvalue(mCount, 1); param.set_mlock(mCount, lockIndex[mCount]); param.set_start(mCount, rares.start); param.set_end(mCount, rares.end - rares.start == 0 ? 1 : rares.end - rares.start); mCount++; break; } } } Net.Instance.DoAction((int)Message.MESSAGE_ID.ID_MSG_WD_BAP_FITTINGS, param); }