1. 程式人生 > >遊戲中精靈物件的屬性功能設計

遊戲中精靈物件的屬性功能設計

我們大部分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