游戏中精灵对象的属性功能设计

我们大部分it人事可能都玩过游戏,且不止一款游戏,都知道游戏有属性;

在游戏中,包含哪些属性,时候数值策划而定;

属性牵涉三个大问题,

1,属性不管是前期还是后期变更可能会非常大;

2,存在不同的属性系统,比如人物基础属性,坐骑属性,宠物属性等;

3,属性计算;属性最终计算;

第一条和第二条,是非常息息相关的功能块设计;需要做到统一,方便,且可扩展性设计;

有且是对策划在配置各种属性,各种系统中去配置属性,既要他们方便配置,思路清晰,又要方便程序扩展,转化;

  1 package com.game.engine.struct;
  2
  3 import java.io.Serializable;
  4
  5 /**
  6  * 基础属性结果
  7  *
  8  * <br>
  9  * author 失足程序员<br>
 10  * mail [email protected]<br>
 11  * phone 13882122019<br>
 12  */
 13 public class BaseAbility implements Serializable {
 14
 15     private static final long serialVersionUID = 7331996190994084714L;
 16     /**
 17      * 攻击速度
 18      */
 19     private int attackSpeed;
 20     /**
 21      * 力量,1001
 22      */
 23     private int strength;
 24     /**
 25      * 主动,1002
 26      */
 27     private int initiative;
 28     /**
 29      * 智慧,1003
 30      */
 31     private int intelligence;
 32     /**
 33      * 意志,1004
 34      */
 35     private int willpower;
 36     /**
 37      * 体魄,1005
 38      */
 39     private int wounds;
 40     //物理攻击下限
 41     private int dcmin;
 42     //物理攻击上限
 43     private int dcmax;
 44     //魔法攻击下限
 45     private int mcmin;
 46     //魔法攻击上限
 47     private int mcmax;
 48     //物理防御
 49     private int ac;
 50     //魔法防御
 51     private int mac;
 52     //闪避
 53     private int duck;
 54     //命中率
 55     private int hit;
 56     //韧性
 57     private int toughness;
 58     //暴击值(概率)
 59     private int critValuePer;
 60     //暴击值
 61     private int critvalue;
 62     //自动回血
 63     private int autohp;
 64     //战斗中回复
 65     private int auto_battle_hp;
 66     //自动回魔法值
 67     private int automp;
 68     //战斗中回复
 69     private int auto_battle_mp;
 70     //最大血量
 71     private int hpmax;
 72     //最大魔法
 73     private int mpmax;
 74     //升级的最大经验值
 75     private long expmax;
 76     //速度
 77     private int speed;
 78     //物理减伤
 79     private int dcharmdel;
 80     //魔法减伤
 81     private int mcharmdel;
 82     //物理反伤
 83     private int undcharmdel;
 84     //魔法反伤
 85     private int unmcharmdel;
 86     //吸血属性
 87     private int drains;
 88
 89     //--------------上面需要传到前端,下面不需要----------------//
 90     //经验加成
 91     private int expmultiple;
 92
 93     //属性提供的战斗力
 94     private int fight;
 95
 96     public BaseAbility() {
 97     }
 98
 99     public int getAttackSpeed() {
100         return attackSpeed;
101     }
102
103     public void setAttackSpeed(int attackSpeed) {
104         this.attackSpeed = attackSpeed;
105     }
106
107     public int getStrength() {
108         return strength;
109     }
110
111     public void setStrength(int strength) {
112         this.strength = strength;
113     }
114
115     public int getInitiative() {
116         return initiative;
117     }
118
119     public void setInitiative(int initiative) {
120         this.initiative = initiative;
121     }
122
123     public int getIntelligence() {
124         return intelligence;
125     }
126
127     public void setIntelligence(int intelligence) {
128         this.intelligence = intelligence;
129     }
130
131     public int getWillpower() {
132         return willpower;
133     }
134
135     public void setWillpower(int willpower) {
136         this.willpower = willpower;
137     }
138
139     public int getWounds() {
140         return wounds;
141     }
142
143     public void setWounds(int wounds) {
144         this.wounds = wounds;
145     }
146
147     public int getDcmin() {
148         return dcmin;
149     }
150
151     public void setDcmin(int dcmin) {
152         this.dcmin = dcmin;
153     }
154
155     public int getDcmax() {
156         return dcmax;
157     }
158
159     public void setDcmax(int dcmax) {
160         this.dcmax = dcmax;
161     }
162
163     public int getMcmin() {
164         return mcmin;
165     }
166
167     public void setMcmin(int mcmin) {
168         this.mcmin = mcmin;
169     }
170
171     public int getMcmax() {
172         return mcmax;
173     }
174
175     public void setMcmax(int mcmax) {
176         this.mcmax = mcmax;
177     }
178
179     public int getAc() {
180         return ac;
181     }
182
183     public void setAc(int ac) {
184         this.ac = ac;
185     }
186
187     public int getMac() {
188         return mac;
189     }
190
191     public void setMac(int mac) {
192         this.mac = mac;
193     }
194
195     public int getDuck() {
196         return duck;
197     }
198
199     public void setDuck(int duck) {
200         this.duck = duck;
201     }
202
203     public int getHit() {
204         return hit;
205     }
206
207     public void setHit(int hit) {
208         this.hit = hit;
209     }
210
211     public int getToughness() {
212         return toughness;
213     }
214
215     public void setToughness(int toughness) {
216         this.toughness = toughness;
217     }
218
219     public int getCritValuePer() {
220         return critValuePer;
221     }
222
223     public void setCritValuePer(int critValuePer) {
224         this.critValuePer = critValuePer;
225     }
226
227     public int getCritvalue() {
228         return critvalue;
229     }
230
231     public void setCritvalue(int critvalue) {
232         this.critvalue = critvalue;
233     }
234
235     public int getAutohp() {
236         return autohp;
237     }
238
239     public void setAutohp(int autohp) {
240         this.autohp = autohp;
241     }
242
243     public int getAuto_battle_hp() {
244         return auto_battle_hp;
245     }
246
247     public void setAuto_battle_hp(int auto_battle_hp) {
248         this.auto_battle_hp = auto_battle_hp;
249     }
250
251     public int getAutomp() {
252         return automp;
253     }
254
255     public void setAutomp(int automp) {
256         this.automp = automp;
257     }
258
259     public int getAuto_battle_mp() {
260         return auto_battle_mp;
261     }
262
263     public void setAuto_battle_mp(int auto_battle_mp) {
264         this.auto_battle_mp = auto_battle_mp;
265     }
266
267     public int getHpmax() {
268         return hpmax;
269     }
270
271     public void setHpmax(int hpmax) {
272         this.hpmax = hpmax;
273     }
274
275     public int getMpmax() {
276         return mpmax;
277     }
278
279     public void setMpmax(int mpmax) {
280         this.mpmax = mpmax;
281     }
282
283     public long getExpmax() {
284         return expmax;
285     }
286
287     public void setExpmax(long expmax) {
288         this.expmax = expmax;
289     }
290
291     public int getSpeed() {
292         return speed;
293     }
294
295     public void setSpeed(int speed) {
296         this.speed = speed;
297     }
298
299     public int getDcharmdel() {
300         return dcharmdel;
301     }
302
303     public void setDcharmdel(int dcharmdel) {
304         this.dcharmdel = dcharmdel;
305     }
306
307     public int getMcharmdel() {
308         return mcharmdel;
309     }
310
311     public void setMcharmdel(int mcharmdel) {
312         this.mcharmdel = mcharmdel;
313     }
314
315     public int getUndcharmdel() {
316         return undcharmdel;
317     }
318
319     public void setUndcharmdel(int undcharmdel) {
320         this.undcharmdel = undcharmdel;
321     }
322
323     public int getUnmcharmdel() {
324         return unmcharmdel;
325     }
326
327     public void setUnmcharmdel(int unmcharmdel) {
328         this.unmcharmdel = unmcharmdel;
329     }
330
331     public int getDrains() {
332         return drains;
333     }
334
335     public void setDrains(int drains) {
336         this.drains = drains;
337     }
338
339     public int getExpmultiple() {
340         return expmultiple;
341     }
342
343     public void setExpmultiple(int expmultiple) {
344         this.expmultiple = expmultiple;
345     }
346
347     public int getFight() {
348         return fight;
349     }
350
351     public void setFight(int fight) {
352         this.fight = fight;
353     }
354
355     /**
356      * 属性清零
357      *
358      */
359     public void clearZero() {
360         this.strength = 0;
361         /**
362          * 主动,1002
363          */
364         this.initiative = 0;
365         /**
366          * 智慧,1003
367          */
368         this.intelligence = 0;
369         /**
370          * 意志,1004
371          */
372         this.willpower = 0;
373         /**
374          * 体魄,1005
375          */
376         this.wounds = 0;
377         this.attackSpeed = 0;
378         this.dcmin = 0;
379         this.dcmax = 0;
380         this.mcmin = 0;
381         this.mcmax = 0;
382         this.ac = 0;
383         this.mac = 0;
384         this.duck = 0;
385         this.hit = 0;
386         this.toughness = 0;
387         this.critvalue = 0;
388         this.critValuePer = 0;
389         this.autohp = 0;
390         this.auto_battle_hp = 0;
391         this.automp = 0;
392         this.auto_battle_mp = 0;
393         this.hpmax = 0;
394         this.mpmax = 0;
395         this.expmax = 0;
396         this.speed = 0;
397         this.dcharmdel = 0;
398         this.undcharmdel = 0;
399         this.mcharmdel = 0;
400         this.unmcharmdel = 0;
401         this.expmultiple = 0;
402         this.drains = 0;
403         this.fight = 0;
404     }
405
406     /**
407      * 属性小于0的处理
408      */
409     public void zeroAbility() {
410         this.strength = this.strength > 0 ? this.strength : 0;
411         /**
412          * 主动,1002
413          */
414         this.initiative = this.initiative > 0 ? this.initiative : 0;
415         /**
416          * 智慧,1003
417          */
418         this.intelligence = this.intelligence > 0 ? this.intelligence : 0;
419         /**
420          * 意志,1004
421          */
422         this.willpower = this.willpower > 0 ? this.willpower : 0;
423         /**
424          * 体魄,1005
425          */
426         this.wounds = this.wounds > 0 ? this.wounds : 0;
427         this.attackSpeed = this.attackSpeed > 0 ? this.attackSpeed : 0;
428         this.dcmin = this.dcmin > 0 ? this.dcmin : 0;
429         this.dcmax = this.dcmax > 0 ? this.dcmax : 0;
430         this.mcmin = this.mcmin > 0 ? this.mcmin : 0;
431         this.mcmax = this.mcmax > 0 ? this.mcmax : 0;
432         this.ac = this.ac > 0 ? this.ac : 0;
433         this.mac = this.mac > 0 ? this.mac : 0;
434         this.duck = this.duck > 0 ? this.duck : 0;
435         this.hit = this.hit > 0 ? this.hit : 0;
436         this.toughness = this.toughness > 0 ? this.toughness : 0;
437         this.critvalue = this.critvalue > 0 ? this.critvalue : 0;
438         this.critValuePer = this.critValuePer > 0 ? this.critValuePer : 0;
439         this.autohp = this.autohp > 0 ? this.autohp : 0;
440         this.auto_battle_hp = this.auto_battle_hp > 0 ? this.auto_battle_hp : 0;
441         this.automp = this.automp > 0 ? this.automp : 0;
442         this.auto_battle_mp = this.auto_battle_mp > 0 ? this.auto_battle_mp : 0;
443         this.hpmax = this.hpmax > 0 ? this.hpmax : 0;
444         this.mpmax = this.mpmax > 0 ? this.mpmax : 0;
445         this.expmax = this.expmax > 0 ? this.expmax : 0;
446         this.speed = this.speed < 0 ? 0 : (this.speed > 8000 ? 8000 : this.speed); // 移动速度介于 0 -8000
447         this.dcharmdel = this.dcharmdel > 0 ? this.dcharmdel : 0;
448         this.undcharmdel = this.undcharmdel > 0 ? this.undcharmdel : 0;
449         this.mcharmdel = this.mcharmdel > 0 ? this.mcharmdel : 0;
450         this.unmcharmdel = this.unmcharmdel > 0 ? this.unmcharmdel : 0;
451         this.expmultiple = this.expmultiple > 0 ? this.expmultiple : 0;
452         this.drains = this.drains > 0 ? this.drains : 0;
453     }
454
455     @Override
456     public String toString() {
457         return "BaseAbility{" + "attackSpeed=" + attackSpeed + ", strength=" + strength + ", initiative=" + initiative + ", intelligence=" + intelligence + ", willpower=" + willpower + ", wounds=" + wounds + ", dcmin=" + dcmin + ", dcmax=" + dcmax + ", mcmin=" + mcmin + ", mcmax=" + mcmax + ", ac=" + ac + ", mac=" + mac + ", duck=" + duck + ", hit=" + hit + ", toughness=" + toughness + ", crit=" + critValuePer + ", critvalue=" + critvalue + ", autohp=" + autohp + ", auto_battle_hp=" + auto_battle_hp + ", automp=" + automp + ", auto_battle_mp=" + auto_battle_mp + ", hpmax=" + hpmax + ", mpmax=" + mpmax + ", expmax=" + expmax + ", speed=" + speed + ", dcharmdel=" + dcharmdel + ", mcharmdel=" + mcharmdel + ", undcharmdel=" + undcharmdel + ", unmcharmdel=" + unmcharmdel + ", drains=" + drains + ", expmultiple=" + expmultiple + ", fight=" + fight + ‘}‘;
458     }
459
460 }

这个类是用于服务器程序计算的,

  1 package com.game.engine.struct;
  2
  3 import com.game.engine.struct.PersonAttribute.AttKey;
  4 import java.util.concurrent.ConcurrentHashMap;
  5 import net.sz.engine.utils.RandomUtils;
  6 import org.apache.log4j.Logger;
  7
  8 /**
  9  * 属性
 10  * <br>
 11  * author 失足程序员<br>
 12  * mail [email protected]<br>
 13  * phone 13882122019<br>
 14  */
 15 public class PersonAttribute extends ConcurrentHashMap<AttKey, Integer> {
 16
 17     private static final Logger log = Logger.getLogger(PersonAttribute.class);
 18
 19     private static final long serialVersionUID = -3258690074056212218L;
 20     private Long expMax = 0l;
 21
 22     public enum AttKey {
 23
 24         /**
 25          * 120, "最大开孔数"
 26          */
 27         EGAP_KONGMAX(120, "最大开孔数"),
 28         /**
 29          * 121, "当前开孔数"
 30          */
 31         EGAP_KONG(121, "当前开孔数"),
 32         /**
 33          * 122, "孔1"
 34          */
 35         EGAP_KONG_1(122, "孔1"),
 36         /**
 37          * 123, "孔2"
 38          */
 39         EGAP_KONG_2(123, "孔2"),
 40         /**
 41          * 124, "孔3"
 42          */
 43         EGAP_KONG_3(124, "孔3"),
 44         /**
 45          * 125, "孔4"
 46          */
 47         EGAP_KONG_4(125, "孔4"),
 48         /**
 49          * 126, "孔5"
 50          */
 51         EGAP_KONG_5(126, "孔5"),
 52         /**
 53          * 144, "精炼消耗"
 54          */
 55         REFINE_Star_Cost(144, "精炼消耗"),
 56         /**
 57          * 力量,1001
 58          */
 59         Strength(1001, "力量"),
 60         /**
 61          * 主动,1002
 62          */
 63         Initiative(1002, "主动"),
 64         /**
 65          * 智慧,1003
 66          */
 67         Intelligence(1003, "智慧"),
 68         /**
 69          * 意志,1004
 70          */
 71         Willpower(1004, "意志"),
 72         /**
 73          * 体魄,1005
 74          */
 75         Wounds(1005, "体魄"),
 76         /**
 77          * 物理攻击下限,2001
 78          */
 79         DCmin(2001, "物理攻击下限"),
 80         /**
 81          * 物理攻击上限,2002
 82          */
 83         DCmax(2002, "物理攻击上限"),
 84         /**
 85          * 物理攻击增加,2003
 86          */
 87         DCcount(2003, "物理攻击增加"),
 88         /**
 89          * 物理攻击万分比提升,2004
 90          */
 91         DCper(2004, "物理攻击万分比提升"),
 92         /**
 93          * 魔法攻击下限,2011
 94          */
 95         MCmin(2011, "魔法攻击下限"),
 96         /**
 97          * 魔法攻击上限,2012
 98          */
 99         MCmax(2012, "魔法攻击上限"),
100         /**
101          * 魔法攻击增加,2013
102          */
103         MCcount(2013, "魔法攻击增加"),
104         /**
105          * 魔法攻击万分比提升,2014
106          */
107         MCper(2014, "魔法攻击万分比提升"),
108         /**
109          * 物理防御上限,2021
110          */
111         AC(2021, "物理防御"),
112         /**
113          * 物防增加,2023
114          */
115         ACCount(2023, "物防增加"),
116         /**
117          * 物理防御万分比提升,2024
118          */
119         ACPer(2024, "物理防御万分比提升"),
120         /**
121          * 魔法防御上限,2031
122          */
123         Mac(2031, "魔法防御"),
124         /**
125          * 魔防增加,2033
126          */
127         MacCount(2033, "魔防增加"),
128         /**
129          * 魔法防御万分比提升,2034
130          */
131         MacPer(2034, "魔法防御万分比提升"),
132         /**
133          * 最大魔法,2041
134          */
135         MpMax(2041, "最大魔法"),
136         /**
137          * 最大魔法万分比提升,2042
138          */
139         MPMaxper(2042, "最大魔法万分比提升"),
140         /**
141          * 当前魔法回复(战斗状态),2043
142          */
143         MPFightCount(2043, "当前魔法回复(战斗状态)"),
144         /**
145          * 当前魔法回复(非战斗状态),2044
146          */
147         MPCount(2044, "当前魔法回复(非战斗状态)"),
148         /**
149          * 当前魔法值回复万分比,2045
150          */
151         MPPer(2045, "当前魔法值回复万分比"),
152         /**
153          * 当前魔法值,2046
154          */
155         MP(2047, "当前魔法值"),
156         /**
157          * 自动回复生命,2058
158          */
159         AutoMP(2048, "自动回复魔法值"),
160         /**
161          * 战斗状态自动回复魔法值,2049
162          */
163         AutoBattleMP(2049, "战斗状态自动回复魔法值"),
164         /**
165          * 最大血量,2051
166          */
167         HPMax(2051, "最大血量"),
168         /**
169          * 最大血量万分比提升,2052
170          */
171         HPMaxper(2052, "最大血量万分比提升"),
172         /**
173          * 当前生命回复(战斗状态),2053
174          */
175         HPFightCount(2053, "当前生命回复(战斗状态)"),
176         /**
177          * 当前生命回复(非战斗状态),2054
178          */
179         HPCount(2054, "当前生命回复(非战斗状态)"),
180         /**
181          * 当前生命回复万分比,2055
182          */
183         HPPer(2055, "当前生命回复万分比"),
184         /**
185          * 当前生命,2057
186          */
187         HP(2057, "当前生命"),
188         /**
189          * 自动回复生命,2058
190          */
191         AutoHP(2058, "自动回复生命"),
192         /**
193          * 战斗状态自动回复生命,2059
194          */
195         AutoBattleHP(2059, "战斗状态自动回复生命"),
196         /**
197          * 闪避,2061
198          */
199         Dcuk(2061, "闪避"),
200         /**
201          * 韧性,2071
202          */
203         Toughness(2071, "韧性"),
204         /**
205          * 命中准确,2081
206          */
207         Hit(2081, "命中准确"),
208         /**
209          * 暴击,2091
210          */
211         CritValue(2091, "暴击"),
212         /**
213          * 物理伤害减免,2101
214          */
215         DCharmdel(2101, "物理伤害减免"),
216         /**
217          * 魔法减伤,2111
218          */
219         MCharmdel(2111, "魔法减伤"),
220         /**
221          * 物理反伤,2121
222          */
223         UnDCharmdel(2121, "物理反伤"),
224         /**
225          * 魔法反伤,2131
226          */
227         UnMCharmdel(2131, "魔法反伤"),
228         /**
229          * 暴击伤害加成的倍率,2141
230          */
231         CritValuePer(2141, "暴击伤害加成的倍率"),
232         /**
233          * 2151, "升级所需经验值"
234          */
235         //        ExpMax(2151, "升级所需经验值"),
236         /**
237          * 当前经验值,2152
238          */
239         Exp(2152, "获得经验值"),
240         /**
241          * 经验加成(万分比),2153
242          */
243         ExpPer(2153, "经验加成(万分比)"),
244         /**
245          * 经验加成(固定点数),2154
246          */
247         ExpCount(2154, "经验加成(固定点数)"),
248         /**
249          * 移动速度,2161
250          */
251         Speed(2161, "移动速度"),
252         /**
253          * 移动速度加成(万分比),2162
254          */
255         SpeedPer(2162, "移动速度加成(万分比)"),
256         /**
257          * 移动速度加成(点数),2163
258          */
259         SpeedCount(2163, "移动速度加成(点数)"),
260         /**
261          * 攻击速度
262          */
263         AttackSpeed(2171, "攻击速度"),
264         /**
265          * 3001, "反伤盾所用的根据攻击力计算,根据不同的职业用不同的攻击力"
266          */
267         AttackPower(3001, "反伤盾所用的根据攻击力计算,根据不同的职业用不同的攻击力"),
268         /**
269          * 9993, "赠送道具"
270          */
271         Goods(9993, "赠送道具"),
272         /**
273          * 9994,魔法和生命值都加
274          */
275         HPMP(9994, "魔法和生命值都加"),
276         /**
277          * 9995,魔法和生命值都加,百分比
278          */
279         HPMPPer(9995, "魔法和生命值都加,百分比"),
280         /**
281          * 9996, vip经验
282          */
283         VIPExp(9996, "vip经验"),
284         /**
285          * 9997, "buff效果"
286          */
287         BuffState(9997, "buff效果"),
288         /**
289          * 9998, "脚本执行"
290          */
291         SCRIPT(9998, "脚本执行"),
292         /**
293          * 战斗力,9999
294          */
295         Fight(9999, "战斗力");
296
297         private int key;
298         private String value;
299
300         private AttKey(int key, String value) {
301             this.key = key;
302             this.value = value;
303         }
304
305         /**
306          * 根据索引获取key
307          *
308          * @param key
309          * @return
310          */
311         public static AttKey parse(int key) {
312             AttKey[] values = AttKey.values();
313             for (AttKey value : values) {
314                 if (value.getKey() == key) {
315                     return value;
316                 }
317             }
318             return null;
319         }
320
321         /**
322          *
323          * @param key
324          * @return
325          */
326         public static AttKey parse(String key) {
327             return Enum.valueOf(AttKey.class, key);
328         }
329
330         /**
331          * 键值
332          *
333          * @return
334          */
335         public int getKey() {
336             return key;
337         }
338
339         /**
340          * 描述字符
341          *
342          * @return
343          */
344         public String getValue() {
345             return value;
346         }
347
348     }
349
350     @Override
351     public Integer put(AttKey key, Integer value) {
352         return super.put(key, value); //To change body of generated methods, choose Tools | Templates.
353     }
354
355     /**
356      * 重写,如果没有建会返回0而不是null
357      *
358      * @param key
359      * @return
360      */
361     @Override
362     public Integer get(Object key) {
363         Integer value = super.get(key);
364         if (value != null) {
365             return value;
366         }
367         return 0;
368     }
369
370     /**
371      * 仅限buff计算调用
372      * <br>
373      * 慎重调用
374      *
375      * @param job 职业编号
376      * @param baseAbility
377      * @param attKey
378      */
379     @Deprecated
380     public static int getBuffAbility(int job, BaseAbility baseAbility, AttKey attKey) {
381         int value = 0;
382         switch (attKey) {
383             case AttackPower: //
384             {
385                 switch (job) {
386                     //物理系列
387                     case 1://骑士
388                     case 3://射手
389                     case 5://屠杀者
390                         value = RandomUtils.random(baseAbility.getDcmin(), baseAbility.getDcmax());
391                         break;
392                     //魔法系列
393                     case 2://法师
394                     case 4://刺客
395                         value = RandomUtils.random(baseAbility.getMcmin(), baseAbility.getMcmax());
396                         break;
397                 }
398             }
399             break;
400             case AC:
401             case ACCount:
402                 value = baseAbility.getAc();
403                 break;
404             case AttackSpeed:
405                 value = baseAbility.getAttackSpeed();
406                 break;
407             case AutoBattleHP:
408                 value = baseAbility.getAuto_battle_hp();
409                 break;
410             case AutoBattleMP:
411                 value = baseAbility.getAuto_battle_mp();
412                 break;
413             case AutoHP:
414                 value = baseAbility.getAutohp();
415                 break;
416             case AutoMP:
417                 value = baseAbility.getAutomp();
418                 break;
419             case CritValue:
420                 value = baseAbility.getCritvalue();
421                 break;
422             case CritValuePer:
423                 value = baseAbility.getCritValuePer();
424                 break;
425             case DCharmdel:
426                 value = baseAbility.getDcharmdel();
427                 break;
428             case DCmin:
429             case DCmax:
430                 value = RandomUtils.random(baseAbility.getDcmin(), baseAbility.getDcmax());
431                 break;
432             case Dcuk:
433                 value = baseAbility.getDuck();
434                 break;
435             case Fight:
436                 value = baseAbility.getFight();
437                 break;
438             case HPMax:
439                 value = baseAbility.getHpmax();
440                 break;
441             case Hit:
442                 value = baseAbility.getHit();
443                 break;
444             case Initiative:
445                 value = baseAbility.getInitiative();
446                 break;
447             case Intelligence:
448                 value = baseAbility.getIntelligence();
449                 break;
450             case MCharmdel:
451                 value = baseAbility.getMcharmdel();
452                 break;
453             case MCmax:
454             case MCmin:
455                 value = RandomUtils.random(baseAbility.getMcmin(), baseAbility.getMcmax());
456                 break;
457             case Mac:
458             case MacCount:
459                 value = baseAbility.getMac();
460                 break;
461             case MpMax:
462                 value = baseAbility.getMpmax();
463                 break;
464             case Strength:
465                 value = baseAbility.getStrength();
466                 break;
467             case Speed:
468             case SpeedCount:
469                 value = baseAbility.getSpeed();
470                 break;
471             case Toughness:
472                 value = baseAbility.getToughness();
473                 break;
474             case UnDCharmdel:
475                 value = baseAbility.getUndcharmdel();
476                 break;
477             case UnMCharmdel:
478                 value = baseAbility.getUnmcharmdel();
479                 break;
480             case Willpower:
481                 value = baseAbility.getWillpower();
482                 break;
483             case Wounds:
484                 value = baseAbility.getWounds();
485                 break;
486         }
487         return value;
488     }
489
490     /**
491      * 构建属性
492      * <br>
493      * 慎重调用
494      *
495      * @param baseAbility
496      */
497     @Deprecated
498     public void buildBaseAbility(BaseAbility baseAbility) {
499         baseAbility.setExpmax(baseAbility.getExpmax() + this.getExpMax());
500         for (Entry<AttKey, Integer> entry : this.entrySet()) {
501             AttKey key = entry.getKey();
502             Integer value = entry.getValue();
503             switch (key) {
504                 case AC:
505                 case ACCount:
506                     baseAbility.setAc(baseAbility.getAc() + value);
507                     break;
508                 case AttackSpeed:
509                     baseAbility.setAttackSpeed(baseAbility.getAttackSpeed() + value);
510                     break;
511                 case AutoBattleHP:
512                     baseAbility.setAuto_battle_hp(baseAbility.getAuto_battle_hp() + value);
513                     break;
514                 case AutoBattleMP:
515                     baseAbility.setAuto_battle_mp(baseAbility.getAuto_battle_mp() + value);
516                     break;
517                 case AutoHP:
518                     baseAbility.setAutohp(baseAbility.getAutohp() + value);
519                     break;
520                 case AutoMP:
521                     baseAbility.setAutomp(baseAbility.getAutomp() + value);
522                     break;
523                 case CritValue:
524                     baseAbility.setCritvalue(baseAbility.getCritvalue() + value);
525                     break;
526                 case CritValuePer:
527                     baseAbility.setCritValuePer(baseAbility.getCritValuePer() + value);
528                     break;
529                 case DCcount:
530                     baseAbility.setDcmin(baseAbility.getDcmin() + value);
531                     baseAbility.setDcmax(baseAbility.getDcmax() + value);
532                     break;
533                 case DCharmdel:
534                     baseAbility.setDcharmdel(baseAbility.getDcharmdel() + value);
535                     break;
536                 case DCmax:
537                     baseAbility.setDcmax(baseAbility.getDcmax() + value);
538                     break;
539                 case DCmin:
540                     baseAbility.setDcmin(baseAbility.getDcmin() + value);
541                     break;
542                 case Dcuk:
543                     baseAbility.setDuck(baseAbility.getDuck() + value);
544                     break;
545                 case Fight:
546                     baseAbility.setFight(baseAbility.getFight() + value);
547                     break;
548                 case HPMax:
549                     baseAbility.setHpmax(baseAbility.getHpmax() + value);
550                     break;
551                 case Hit:
552                     baseAbility.setHit(baseAbility.getHit() + value);
553                     break;
554                 case Initiative:
555                     baseAbility.setInitiative(baseAbility.getInitiative() + value);
556                     break;
557                 case Intelligence:
558                     baseAbility.setIntelligence(baseAbility.getIntelligence() + value);
559                     break;
560                 case MCcount:
561                     baseAbility.setMcmin(baseAbility.getMcmin() + value);
562                     baseAbility.setMcmax(baseAbility.getMcmax() + value);
563                     break;
564                 case MCharmdel:
565                     baseAbility.setMcharmdel(baseAbility.getMcharmdel() + value);
566                     break;
567                 case MCmax:
568                     baseAbility.setMcmax(baseAbility.getMcmax() + value);
569                     break;
570                 case MCmin:
571                     baseAbility.setMcmin(baseAbility.getMcmin() + value);
572                     break;
573                 case Mac:
574                 case MacCount:
575                     baseAbility.setMac(baseAbility.getMac() + value);
576                     break;
577                 case MpMax:
578                     baseAbility.setMpmax(baseAbility.getMpmax() + value);
579                     break;
580                 case Strength:
581                     baseAbility.setStrength(baseAbility.getStrength() + value);
582                     break;
583                 case Speed:
584                 case SpeedCount:
585                     baseAbility.setSpeed(baseAbility.getSpeed() + value);
586                     break;
587                 case Toughness:
588                     baseAbility.setToughness(baseAbility.getToughness() + value);
589                     break;
590                 case UnDCharmdel:
591                     baseAbility.setUndcharmdel(baseAbility.getUndcharmdel() + value);
592                     break;
593                 case UnMCharmdel:
594                     baseAbility.setUnmcharmdel(baseAbility.getUnmcharmdel() + value);
595                     break;
596                 case Willpower:
597                     baseAbility.setWillpower(baseAbility.getWillpower() + value);
598                     break;
599                 case Wounds:
600                     baseAbility.setWounds(baseAbility.getWounds() + value);
601                     break;
602             }
603         }
604     }
605
606     /**
607      * 构建属性,构建属性集合中比例属性加成,万分比格式
608      * <br>
609      * 慎重调用
610      *
611      * @param baseAbility
612      */
613     @Deprecated
614     public void buildBaseAbilityPer(BaseAbility baseAbility) {
615         for (Entry<AttKey, Integer> entry : this.entrySet()) {
616             AttKey key = entry.getKey();
617             Integer value = entry.getValue();
618             switch (key) {
619                 case ACPer:
620                     baseAbility.setAc(baseAbility.getAc() + (int) (baseAbility.getAc() * (value / 10000D)));
621                     break;
622                 case DCper:
623                     baseAbility.setDcmin(baseAbility.getDcmin() + (int) (baseAbility.getDcmin() * (value / 10000D)));
624                     baseAbility.setDcmax(baseAbility.getDcmax() + (int) (baseAbility.getDcmax() * (value / 10000D)));
625                     break;
626                 case HPMaxper:
627                     baseAbility.setHpmax(baseAbility.getHpmax() + (int) (baseAbility.getHpmax() * (value / 10000D)));
628                     break;
629                 case MCper:
630                     baseAbility.setMcmin(baseAbility.getMcmin() + (int) (baseAbility.getMcmin() * (value / 10000D)));
631                     baseAbility.setMcmax(baseAbility.getMcmax() + (int) (baseAbility.getMcmax() * (value / 10000D)));
632                     break;
633                 case MacPer:
634                     baseAbility.setMac(baseAbility.getMac() + (int) (baseAbility.getMac() * (value / 10000D)));
635                     break;
636                 case SpeedPer:
637                     baseAbility.setSpeed(baseAbility.getSpeed() + (int) (baseAbility.getSpeed() * (value / 10000D)));
638                     break;
639             }
640         }
641     }
642
643     @Override
644     public String toString() {
645         for (Entry<AttKey, Integer> entry : this.entrySet()) {
646             AttKey key = entry.getKey();
647             Integer value = entry.getValue();
648         }
649         return "PlayerAttribute{" + ‘}‘;
650     }
651
652     /**
653      * 所有属性清零
654      */
655     public void clearZoer() {
656         for (Entry<AttKey, Integer> entry : this.entrySet()) {
657             AttKey key = entry.getKey();
658             Integer value = entry.getValue();
659             this.put(key, 0);
660         }
661     }
662
663     /**
664      * 累计
665      *
666      * @param playerAttribute
667      */
668     public void add(PersonAttribute playerAttribute) {
669         for (Entry<AttKey, Integer> entry : playerAttribute.entrySet()) {
670             AttKey key = entry.getKey();
671             Integer value = entry.getValue();
672             Integer get = this.get(key);
673             value += get;
674             this.put(key, value);
675         }
676         this.expMax += playerAttribute.expMax;
677     }
678
679     /**
680      *
681      * @param key
682      * @param value
683      */
684     public void add(int key, Integer value) {
685         add(AttKey.parse(key), value);
686     }
687
688     /**
689      *
690      * @param key
691      * @param value
692      */
693     public void add(AttKey key, Integer value) {
694         if (key != null) {
695             Integer get = this.get(key);
696             value += get;
697             this.put(key, value);
698         }
699     }
700
701     public Long getExpMax() {
702         return expMax;
703     }
704
705     public void setExpMax(Long expMax) {
706         this.expMax = expMax;
707     }
708
709     public static void main(String[] args) {
710         String toString = PersonAttribute.AttKey.Initiative.toString();
711         System.out.println(toString);
712         System.out.println(PersonAttribute.AttKey.parse(toString).getValue());
713     }
714 }

这个类用于策划配置方式解析的,

策划在配置属性的时候只需要配置出来,就能通用解析。

 1     // <editor-fold defaultstate="collapsed" desc="返回属性键值对 public static void getAttribute(PersonAttribute attribute, String attString)">
 2     /**
 3      * 返回属性键值对
 4      *
 5      * @param attribute
 6      * @param attString 配置的属性
 7      */
 8     public static void getAttribute(PersonAttribute attribute, String attString) {
 9         if (StringUtil.isNullOrEmpty(attString)) {
10             return;
11         }
12         String[] atts = attString.split(DOUHAO_REG);
13         for (String att : atts) {
14             String[] split = att.split("=");
15             Integer integer = Integer.parseInt(split[0]);
16             Integer integer1 = Integer.parseInt(split[1]);
17             attribute.add(integer, integer1);
18         }
19     }
20     // </editor-fold>
21
22     public static void main(String[] args) {
23         String str = "34052=792,34050=1291,34051=3";
24         PersonAttribute personAttribute = new PersonAttribute();
25         getAttribute(personAttribute, str);
26     }

在精灵对象身上只需要挂载

1     // 属性
2     //最终计算属性
3     protected BaseAbility finalAbility = new BaseAbility();
4
5     //-------------------属性部分-------------------------//
6     private /*transient这样可能会导致离线竞技场角色数据不正确*/ HashMap<Integer, PersonAttribute> attributes = new HashMap<>();
7     //其他属性
8     protected PersonAttribute otherAttribute = new PersonAttribute();

就能分门别类的计算全部属性

 1     @Override
 2     public void computeAttribute(Player player, boolean updateTopListFightPower) {
 3         synchronized (player.abilityLock) {
 4             player.abilityLock.update();
 5
 6             PersonAttribute finalAbility = new PersonAttribute();
 7
 8             HashMap<Integer, PersonAttribute> attributes = player.getAttributes();
 9             //先把非buff的属性计算完成
10             for (Map.Entry<Integer, PersonAttribute> entry : attributes.entrySet()) {
11                 Integer key = entry.getKey();
12                 if (key != PersonAttributeType.BUFF) {
13                     PersonAttribute playerAttribute = entry.getValue();
14                     if (playerAttribute != null) {
15                         finalAbility.add(playerAttribute);
16                     }
17                 }
18             }
19             player.getFinalAbility().clearZero();
20             //构建基础属性
21             finalAbility.buildBaseAbility(player.getFinalAbility());
22             finalAbility.buildBaseAbilityPer(player.getFinalAbility());
23
24             //清零后计算buff
25             finalAbility.clear();
26
27             //再计算buff的属性计算完成
28             for (Map.Entry<Integer, PersonAttribute> entry : attributes.entrySet()) {
29                 Integer key = entry.getKey();
30                 if (key == PersonAttributeType.BUFF) {
31                     PersonAttribute playerAttribute = entry.getValue();
32                     if (playerAttribute != null) {
33                         finalAbility.add(playerAttribute);
34                     }
35                 }
36             }
37             //构建基础属性
38             //先计算buff加成
39             finalAbility.buildBaseAbilityPer(player.getFinalAbility());
40             //在计算buff基础点数
41             finalAbility.buildBaseAbility(player.getFinalAbility());
42             //设置经验比例加成
43             player.setExpMultiple(1 + finalAbility.get(PersonAttribute.AttKey.ExpPer)); // 特殊处理经验BUFF经验BUFF
44             player.getFinalAbility().zeroAbility();
45             log.error("当前速度:" + player.getFinalAbility().getSpeed());
46             {
47                 //属性,加成
48                 //物理攻击加成
49                 player.getFinalAbility().setDcmin(player.getFinalAbility().getDcmin() + player.getFinalAbility().getStrength());
50                 player.getFinalAbility().setDcmax(player.getFinalAbility().getDcmax() + player.getFinalAbility().getStrength());
51                 //物理防御
52                 player.getFinalAbility().setAc(player.getFinalAbility().getAc() + player.getFinalAbility().getStrength());
53                 //生命上限
54                 player.getFinalAbility().setHpmax(player.getFinalAbility().getHpmax() + player.getFinalAbility().getWounds() * 8);
55                 //魔法攻击
56                 player.getFinalAbility().setMcmin(player.getFinalAbility().getMcmin() + player.getFinalAbility().getIntelligence());
57                 player.getFinalAbility().setMcmax(player.getFinalAbility().getMcmax() + player.getFinalAbility().getIntelligence());
58                 //魔法防御
59                 player.getFinalAbility().setMac(player.getFinalAbility().getMac() + player.getFinalAbility().getIntelligence());
60                 //魔法值上限
61                 player.getFinalAbility().setMpmax(player.getFinalAbility().getMpmax() + player.getFinalAbility().getIntelligence() * 6);
62                 //闪避
63                 player.getFinalAbility().setDuck(player.getFinalAbility().getDuck() + player.getFinalAbility().getInitiative());
64                 //韧性
65                 player.getFinalAbility().setToughness(player.getFinalAbility().getToughness() + (int) (player.getFinalAbility().getInitiative() * 0.5));
66                 //命中
67                 player.getFinalAbility().setHit(player.getFinalAbility().getHit() + (int) (player.getFinalAbility().getWillpower() * 0.5));
68                 //暴击
69                 player.getFinalAbility().setCritValuePer(player.getFinalAbility().getCritValuePer() + (int) (player.getFinalAbility().getWillpower()));
70
71             }
72
73             if (updateTopListFightPower && !player.isArenaRobot() && player.getLevel() >= TopListManager.SYNC_PLAYER_LEVEL) { // 如BUFF等改变玩家属性,将不触发排行榜
74 //                log.error("玩家战斗力改变,触发战力排行榜");
75                 TopListManager.getInstance().updateAllTopData(player, null, TopListManager.TOP_POWER);
76             }
77         }
78     }

只是我们游戏目前属性计算方式;

没有特别的说明,也没有多少描述,简单的贴出代码和一些思路;

时间: 2024-10-27 21:34:51

游戏中精灵对象的属性功能设计的相关文章

Unity 2D游戏开发教程之游戏中精灵的跳跃状态

Unity 2D游戏开发教程之游戏中精灵的跳跃状态 精灵的跳跃状态 为了让游戏中的精灵有更大的活动范围,上一节为游戏场景添加了多个地面,于是精灵可以从高的地面移动到低的地面处,如图2-14所示.但是却无法从低的地面移动到高的地面,因为当前的游戏精灵只能左右移动,即left和right.为了解决这个问题,本节就来为精灵添加跳跃状态.   图2-14  精灵从一个地面移动到另一个地面 (1)如果要为精灵添加跳跃状态,即jump,就不得不再引入其它状态: q   landing:用于表示精灵接触到地面

swfupload js中 file 对象的属性

name=3cc68cfc60b87e6dd6887d8a.jpg modificationdate=Wed   Apr 21 15:48:30 UTC+0800 2010 filestatus=-1 post=[object   Object] type=.jpg index=0 size=29006 creationdate=Wed Apr 21 15:48:38 UTC+0800   2010 id=SWFUpload_0_0swfupload js中 file 对象的属性,布布扣,bub

[原创]java WEB学习笔记59:Struts2学习之路---OGNL,值栈,读取对象栈中的对象的属性,读取 Context Map 里的对象的属性,调用字段和方法,数组,list,map

本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱好者,互联网技术发烧友 微博:伊直都在0221 QQ:951226918 -----------------------------------------------------------------------------------------------------------------

全面理解Javascript中Function对象的属性和方法

函数是 JavaScript 中的基本数据类型,在函数这个对象上定义了一些属性和方法,下面我们逐一来介绍这些属性和方法,这对于理解Javascript的继承机制具有一定的帮助. 属性(Properties) arguments 获取当前正在执行的 Function 对象的所有参数,是一个类似数组但不是数组的对象,说它类似数组是因为其具有数组一样的访问性质及方式,可以由arguments[n]来访问对应的单个参数的值,并拥有数组长度属性length.还有就是arguments对象存储的是实际传递给

JavaScript中操作对象的属性

1.操作对象的属性 注意: 标签属性与DOM对象属性的对应关系: 绝大部分2者是相同的,如:imgobj.src属性对应<img src="" >中src属性,但也有例外,如<div class="main" >中,操作class属性用divobj.className. CSS属性与DOM对象属性的对应关系: 1. 两者通过obj.style.css属性名 相对应   如:obj.style.width. 2.如果CSS属性带有横线,如bor

js中Array对象的属性和方法总结

一:属性 length length除了常见的读取数组的长度以外,也可以通过修改length的值来给数组增加或者删除元素,当length数值减少的时候,从数组末尾删除相应元素:增加的时候增加相应数量的元素,但是新增元素没有赋值的时候,初始值为undefined; 二:方法 检测数组 if(obj instanceof Array){ //执行对数组的操作 } 但是这种方法有一个问题.当页面由框架组成的时候,不同的框架中的Window对象是不同的,而Array对象实际上是Window对象的一个属性

js中遍历对象的属性和值

今天想看一下js的数组遍历的内容,搜索到了一个关于对象遍历写好的函数,保留一下.以后好用. function allPrpos ( obj ) {   // 用来保存所有的属性名称和值   var props = "" ;   // 开始遍历   for ( var p in obj ){ // 方法   if ( typeof ( obj [ p ]) == " function " ){ obj [ p ]() ;   } else { // p 为属性名称,o

5月15日上课笔记-js中 location对象的属性、document对象、js内置对象、Date事件对象、

location的属性: host: 返回当前主机名和端口号 定时函数: setTimeout( ) setInterval() 二.document对象 getElementById(); 根据ID值获取一个DOM对象 getElementsByName(); 根据name属性值获取多个Dom对象 getElementsByTagName(); 根据标签获取多个DOM对象 获取标签体内容 innerHTML 获取input的value值 value 获取下拉框选中的值 value this 代

Matlab中classperf对象各属性解释[原创]

1.ClassLabels:类型标识.第一个label作为pos,第二次label作为neg. 2.GroundTruth:各次实验的观察值,也就是真实值. 3.ValidationCounter: 测试次数 4.SampleDistribution:每个样本作为测试集样本的次数.如果是k-fold-validation则会有k次. 5.ErrorDistribution:在测试时每个样本被误判的次数 以上2个属性在k-fold-valiation中可以找出误判次数多的样本. 6.SampleD