您的位置:首页 > 其它

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

2016-08-26 16:46 232 查看

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

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

属性牵涉三个大问题,

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

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

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

 

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

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

package com.game.engine.struct;

import java.io.Serializable;

/**
* 基础属性结果
*
* <br>
* author 失足程序员<br>
* mail 492794628@qq.com<br>
* phone 13882122019<br>
*/
public class BaseAbility implements Serializable {

private static final long serialVersionUID = 7331996190994084714L;
/**
* 攻击速度
*/
private int attackSpeed;
/**
* 力量,1001
*/
private int strength;
/**
* 主动,1002
*/
private int initiative;
/**
* 智慧,1003
*/
private int intelligence;
/**
* 意志,1004
*/
private int willpower;
/**
* 体魄,1005
*/
private int wounds;
//物理攻击下限
private int dcmin;
//物理攻击上限
private int dcmax;
//魔法攻击下限
private int mcmin;
//魔法攻击上限
private int mcmax;
//物理防御
private int ac;
//魔法防御
private int mac;
//闪避
private int duck;
//命中率
private int hit;
//韧性
private int toughness;
//暴击值(概率)
private int critValuePer;
//暴击值
private int critvalue;
//自动回血
private int autohp;
//战斗中回复
private int auto_battle_hp;
//自动回魔法值
private int automp;
//战斗中回复
private int auto_battle_mp;
//最大血量
private int hpmax;
//最大魔法
private int mpmax;
//升级的最大经验值
private long expmax;
//速度
private int speed;
//物理减伤
private int dcharmdel;
//魔法减伤
private int mcharmdel;
//物理反伤
private int undcharmdel;
//魔法反伤
private int unmcharmdel;
//吸血属性
private int drains;

//--------------上面需要传到前端,下面不需要----------------//
//经验加成
private int expmultiple;

//属性提供的战斗力
private int fight;

public BaseAbility() {
}

public int getAttackSpeed() {
return attackSpeed;
}

public void setAttackSpeed(int attackSpeed) {
this.attackSpeed = attackSpeed;
}

public int getStrength() {
return strength;
}

public void setStrength(int strength) {
this.strength = strength;
}

public int getInitiative() {
return initiative;
}

public void setInitiative(int initiative) {
this.initiative = initiative;
}

public int getIntelligence() {
return intelligence;
}

public void setIntelligence(int intelligence) {
this.intelligence = intelligence;
}

public int getWillpower() {
return willpower;
}

public void setWillpower(int willpower) {
this.willpower = willpower;
}

public int getWounds() {
return wounds;
}

public void setWounds(int wounds) {
this.wounds = wounds;
}

public int getDcmin() {
return dcmin;
}

public void setDcmin(int dcmin) {
this.dcmin = dcmin;
}

public int getDcmax() {
return dcmax;
}

public void setDcmax(int dcmax) {
this.dcmax = dcmax;
}

public int getMcmin() {
return mcmin;
}

public void setMcmin(int mcmin) {
this.mcmin = mcmin;
}

public int getMcmax() {
return mcmax;
}

public void setMcmax(int mcmax) {
this.mcmax = mcmax;
}

public int getAc() {
return ac;
}

public void setAc(int ac) {
this.ac = ac;
}

public int getMac() {
return mac;
}

public void setMac(int mac) {
this.mac = mac;
}

public int getDuck() {
return duck;
}

public void setDuck(int duck) {
this.duck = duck;
}

public int getHit() {
return hit;
}

public void setHit(int hit) {
this.hit = hit;
}

public int getToughness() {
return toughness;
}

public void setToughness(int toughness) {
this.toughness = toughness;
}

public int getCritValuePer() {
return critValuePer;
}

public void setCritValuePer(int critValuePer) {
this.critValuePer = critValuePer;
}

public int getCritvalue() {
return critvalue;
}

public void setCritvalue(int critvalue) {
this.critvalue = critvalue;
}

public int getAutohp() {
return autohp;
}

public void setAutohp(int autohp) {
this.autohp = autohp;
}

public int getAuto_battle_hp() {
return auto_battle_hp;
}

public void setAuto_battle_hp(int auto_battle_hp) {
this.auto_battle_hp = auto_battle_hp;
}

public int getAutomp() {
return automp;
}

public void setAutomp(int automp) {
this.automp = automp;
}

public int getAuto_battle_mp() {
return auto_battle_mp;
}

public void setAuto_battle_mp(int auto_battle_mp) {
this.auto_battle_mp = auto_battle_mp;
}

public int getHpmax() {
return hpmax;
}

public void setHpmax(int hpmax) {
this.hpmax = hpmax;
}

public int getMpmax() {
return mpmax;
}

public void setMpmax(int mpmax) {
this.mpmax = mpmax;
}

public long getExpmax() {
return expmax;
}

public void setExpmax(long expmax) {
this.expmax = expmax;
}

public int getSpeed() {
return speed;
}

public void setSpeed(int speed) {
this.speed = speed;
}

public int getDcharmdel() {
return dcharmdel;
}

public void setDcharmdel(int dcharmdel) {
this.dcharmdel = dcharmdel;
}

public int getMcharmdel() {
return mcharmdel;
}

public void setMcharmdel(int mcharmdel) {
this.mcharmdel = mcharmdel;
}

public int getUndcharmdel() {
return undcharmdel;
}

public void setUndcharmdel(int undcharmdel) {
this.undcharmdel = undcharmdel;
}

public int getUnmcharmdel() {
return unmcharmdel;
}

public void setUnmcharmdel(int unmcharmdel) {
this.unmcharmdel = unmcharmdel;
}

public int getDrains() {
return drains;
}

public void setDrains(int drains) {
this.drains = drains;
}

public int getExpmultiple() {
return expmultiple;
}

public void setExpmultiple(int expmultiple) {
this.expmultiple = expmultiple;
}

public int getFight() {
return fight;
}

public void setFight(int fight) {
this.fight = fight;
}

/**
* 属性清零
*
*/
public void clearZero() {
this.strength = 0;
/**
* 主动,1002
*/
this.initiative = 0;
/**
* 智慧,1003
*/
this.intelligence = 0;
/**
* 意志,1004
*/
this.willpower = 0;
/**
* 体魄,1005
*/
this.wounds = 0;
this.attackSpeed = 0;
this.dcmin = 0;
this.dcmax = 0;
this.mcmin = 0;
this.mcmax = 0;
this.ac = 0;
this.mac = 0;
this.duck = 0;
this.hit = 0;
this.toughness = 0;
this.critvalue = 0;
this.critValuePer = 0;
this.autohp = 0;
this.auto_battle_hp = 0;
this.automp = 0;
this.auto_battle_mp = 0;
this.hpmax = 0;
this.mpmax = 0;
this.expmax = 0;
this.speed = 0;
this.dcharmdel = 0;
this.undcharmdel = 0;
this.mcharmdel = 0;
this.unmcharmdel = 0;
this.expmultiple = 0;
this.drains = 0;
this.fight = 0;
}

/**
* 属性小于0的处理
*/
public void zeroAbility() {
this.strength = this.strength > 0 ? this.strength : 0;
/**
* 主动,1002
*/
this.initiative = this.initiative > 0 ? this.initiative : 0;
/**
* 智慧,1003
*/
this.intelligence = this.intelligence > 0 ? this.intelligence : 0;
/**
* 意志,1004
*/
this.willpower = this.willpower > 0 ? this.willpower : 0;
/**
* 体魄,1005
*/
this.wounds = this.wounds > 0 ? this.wounds : 0;
this.attackSpeed = this.attackSpeed > 0 ? this.attackSpeed : 0;
this.dcmin = this.dcmin > 0 ? this.dcmin : 0;
this.dcmax = this.dcmax > 0 ? this.dcmax : 0;
this.mcmin = this.mcmin > 0 ? this.mcmin : 0;
this.mcmax = this.mcmax > 0 ? this.mcmax : 0;
this.ac = this.ac > 0 ? this.ac : 0;
this.mac = this.mac > 0 ? this.mac : 0;
this.duck = this.duck > 0 ? this.duck : 0;
this.hit = this.hit > 0 ? this.hit : 0;
this.toughness = this.toughness > 0 ? this.toughness : 0;
this.critvalue = this.critvalue > 0 ? this.critvalue : 0;
this.critValuePer = this.critValuePer > 0 ? this.critValuePer : 0;
this.autohp = this.autohp > 0 ? this.autohp : 0;
this.auto_battle_hp = this.auto_battle_hp > 0 ? this.auto_battle_hp : 0;
this.automp = this.automp > 0 ? this.automp : 0;
this.auto_battle_mp = this.auto_battle_mp > 0 ? this.auto_battle_mp : 0;
this.hpmax = this.hpmax > 0 ? this.hpmax : 0;
this.mpmax = this.mpmax > 0 ? this.mpmax : 0;
this.expmax = this.expmax > 0 ? this.expmax : 0;
this.speed = this.speed < 0 ? 0 : (this.speed > 8000 ? 8000 : this.speed); // 移动速度介于 0 -8000
this.dcharmdel = this.dcharmdel > 0 ? this.dcharmdel : 0;
this.undcharmdel = this.undcharmdel > 0 ? this.undcharmdel : 0;
this.mcharmdel = this.mcharmdel > 0 ? this.mcharmdel : 0;
this.unmcharmdel = this.unmcharmdel > 0 ? this.unmcharmdel : 0;
this.expmultiple = this.expmultiple > 0 ? this.expmultiple : 0;
this.drains = this.drains > 0 ? this.drains : 0;
}

@Override
public String toString() {
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 + '}';
}

}

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

package com.game.engine.struct;

import com.game.engine.struct.PersonAttribute.AttKey;
import java.util.concurrent.ConcurrentHashMap;
import net.sz.engine.utils.RandomUtils;
import org.apache.log4j.Logger;

/**
* 属性
* <br>
* author 失足程序员<br>
* mail 492794628@qq.com<br>
* phone 13882122019<br>
*/
public class PersonAttribute extends ConcurrentHashMap<AttKey, Integer> {

private static final Logger log = Logger.getLogger(PersonAttribute.class);

private static final long serialVersionUID = -3258690074056212218L;
private Long expMax = 0l;

public enum AttKey {

/**
* 120, "最大开孔数"
*/
EGAP_KONGMAX(120, "最大开孔数"),
/**
* 121, "当前开孔数"
*/
EGAP_KONG(121, "当前开孔数"),
/**
* 122, "孔1"
*/
EGAP_KONG_1(122, "孔1"),
/**
* 123, "孔2"
*/
EGAP_KONG_2(123, "孔2"),
/**
* 124, "孔3"
*/
EGAP_KONG_3(124, "孔3"),
/**
* 125, "孔4"
*/
EGAP_KONG_4(125, "孔4"),
/**
* 126, "孔5"
*/
EGAP_KONG_5(126, "孔5"),
/**
* 144, "精炼消耗"
*/
REFINE_Star_Cost(144, "精炼消耗"),
/**
* 力量,1001
*/
Strength(1001, "力量"),
/**
* 主动,1002
*/
Initiative(1002, "主动"),
/**
* 智慧,1003
*/
Intelligence(1003, "智慧"),
/**
* 意志,1004
*/
Willpower(1004, "意志"),
/**
* 体魄,1005
*/
Wounds(1005, "体魄"),
/**
* 物理攻击下限,2001
*/
DCmin(2001, "物理攻击下限"),
/**
* 物理攻击上限,2002
*/
DCmax(2002, "物理攻击上限"),
/**
* 物理攻击增加,2003
*/
DCcount(2003, "物理攻击增加"),
/**
* 物理攻击万分比提升,2004
*/
DCper(2004, "物理攻击万分比提升"),
/**
* 魔法攻击下限,2011
*/
MCmin(2011, "魔法攻击下限"),
/**
* 魔法攻击上限,2012
*/
MCmax(2012, "魔法攻击上限"),
/**
* 魔法攻击增加,2013
*/
MCcount(2013, "魔法攻击增加"),
/**
* 魔法攻击万分比提升,2014
*/
MCper(2014, "魔法攻击万分比提升"),
/**
* 物理防御上限,2021
*/
AC(2021, "物理防御"),
/**
* 物防增加,2023
*/
ACCount(2023, "物防增加"),
/**
* 物理防御万分比提升,2024
*/
ACPer(2024, "物理防御万分比提升"),
/**
* 魔法防御上限,2031
*/
Mac(2031, "魔法防御"),
/**
* 魔防增加,2033
*/
MacCount(2033, "魔防增加"),
/**
* 魔法防御万分比提升,2034
*/
MacPer(2034, "魔法防御万分比提升"),
/**
* 最大魔法,2041
*/
MpMax(2041, "最大魔法"),
/**
* 最大魔法万分比提升,2042
*/
MPMaxper(2042, "最大魔法万分比提升"),
/**
* 当前魔法回复(战斗状态),2043
*/
MPFightCount(2043, "当前魔法回复(战斗状态)"),
/**
* 当前魔法回复(非战斗状态),2044
*/
MPCount(2044, "当前魔法回复(非战斗状态)"),
/**
* 当前魔法值回复万分比,2045
*/
MPPer(2045, "当前魔法值回复万分比"),
/**
* 当前魔法值,2046
*/
MP(2047, "当前魔法值"),
/**
* 自动回复生命,2058
*/
AutoMP(2048, "自动回复魔法值"),
/**
* 战斗状态自动回复魔法值,2049
*/
AutoBattleMP(2049, "战斗状态自动回复魔法值"),
/**
* 最大血量,2051
*/
HPMax(2051, "最大血量"),
/**
* 最大血量万分比提升,2052
*/
HPMaxper(2052, "最大血量万分比提升"),
/**
* 当前生命回复(战斗状态),2053
*/
HPFightCount(2053, "当前生命回复(战斗状态)"),
/**
* 当前生命回复(非战斗状态),2054
*/
HPCount(2054, "当前生命回复(非战斗状态)"),
/**
* 当前生命回复万分比,2055
*/
HPPer(2055, "当前生命回复万分比"),
/**
* 当前生命,2057
*/
HP(2057, "当前生命"),
/**
* 自动回复生命,2058
*/
AutoHP(2058, "自动回复生命"),
/**
* 战斗状态自动回复生命,2059
*/
AutoBattleHP(2059, "战斗状态自动回复生命"),
/**
* 闪避,2061
*/
Dcuk(2061, "闪避"),
/**
* 韧性,2071
*/
Toughness(2071, "韧性"),
/**
* 命中准确,2081
*/
Hit(2081, "命中准确"),
/**
* 暴击,2091
*/
CritValue(2091, "暴击"),
/**
* 物理伤害减免,2101
*/
DCharmdel(2101, "物理伤害减免"),
/**
* 魔法减伤,2111
*/
MCharmdel(2111, "魔法减伤"),
/**
* 物理反伤,2121
*/
UnDCharmdel(2121, "物理反伤"),
/**
* 魔法反伤,2131
*/
UnMCharmdel(2131, "魔法反伤"),
/**
* 暴击伤害加成的倍率,2141
*/
CritValuePer(2141, "暴击伤害加成的倍率"),
/**
* 2151, "升级所需经验值"
*/
//        ExpMax(2151, "升级所需经验值"),
/**
* 当前经验值,2152
*/
Exp(2152, "获得经验值"),
/**
* 经验加成(万分比),2153
*/
ExpPer(2153, "经验加成(万分比)"),
/**
* 经验加成(固定点数),2154
*/
ExpCount(2154, "经验加成(固定点数)"),
/**
* 移动速度,2161
*/
Speed(2161, "移动速度"),
/**
* 移动速度加成(万分比),2162
*/
SpeedPer(2162, "移动速度加成(万分比)"),
/**
* 移动速度加成(点数),2163
*/
SpeedCount(2163, "移动速度加成(点数)"),
/**
* 攻击速度
*/
AttackSpeed(2171, "攻击速度"),
/**
* 3001, "反伤盾所用的根据攻击力计算,根据不同的职业用不同的攻击力"
*/
AttackPower(3001, "反伤盾所用的根据攻击力计算,根据不同的职业用不同的攻击力"),
/**
* 9993, "赠送道具"
*/
Goods(9993, "赠送道具"),
/**
* 9994,魔法和生命值都加
*/
HPMP(9994, "魔法和生命值都加"),
/**
* 9995,魔法和生命值都加,百分比
*/
HPMPPer(9995, "魔法和生命值都加,百分比"),
/**
* 9996, vip经验
*/
VIPExp(9996, "vip经验"),
/**
* 9997, "buff效果"
*/
BuffState(9997, "buff效果"),
/**
* 9998, "脚本执行"
*/
SCRIPT(9998, "脚本执行"),
/**
* 战斗力,9999
*/
Fight(9999, "战斗力");

private int key;
private String value;

private AttKey(int key, String value) {
this.key = key;
this.value = value;
}

/**
* 根据索引获取key
*
* @param key
* @return
*/
public static AttKey parse(int key) {
AttKey[] values = AttKey.values();
for (AttKey value : values) {
if (value.getKey() == key) {
return value;
}
}
return null;
}

/**
*
* @param key
* @return
*/
public static AttKey parse(String key) {
return Enum.valueOf(AttKey.class, key);
}

/**
* 键值
*
* @return
*/
public int getKey() {
return key;
}

/**
* 描述字符
*
* @return
*/
public String getValue() {
return value;
}

}

@Override
public Integer put(AttKey key, Integer value) {
return super.put(key, value); //To change body of generated methods, choose Tools | Templates.
}

/**
* 重写,如果没有建会返回0而不是null
*
* @param key
* @return
*/
@Override
public Integer get(Object key) {
Integer value = super.get(key);
if (value != null) {
return value;
}
return 0;
}

/**
* 仅限buff计算调用
* <br>
* 慎重调用
*
* @param job 职业编号
* @param baseAbility
* @param attKey
*/
@Deprecated
public static int getBuffAbility(int job, BaseAbility baseAbility, AttKey attKey) {
int value = 0;
switch (attKey) {
case AttackPower: //
{
switch (job) {
//物理系列
case 1://骑士
case 3://射手
case 5://屠杀者
value = RandomUtils.random(baseAbility.getDcmin(), baseAbility.getDcmax());
break;
//魔法系列
case 2://法师
case 4://刺客
value = RandomUtils.random(baseAbility.getMcmin(), baseAbility.getMcmax());
break;
}
}
break;
case AC:
case ACCount:
value = baseAbility.getAc();
break;
case AttackSpeed:
value = baseAbility.getAttackSpeed();
break;
case AutoBattleHP:
value = baseAbility.getAuto_battle_hp();
break;
case AutoBattleMP:
value = baseAbility.getAuto_battle_mp();
break;
case AutoHP:
value = baseAbility.getAutohp();
break;
case AutoMP:
value = baseAbility.getAutomp();
break;
case CritValue:
value = baseAbility.getCritvalue();
break;
case CritValuePer:
value = baseAbility.getCritValuePer();
break;
case DCharmdel:
value = baseAbility.getDcharmdel();
break;
case DCmin:
case DCmax:
value = RandomUtils.random(baseAbility.getDcmin(), baseAbility.getDcmax());
break;
case Dcuk:
value = baseAbility.getDuck();
break;
case Fight:
value = baseAbility.getFight();
break;
case HPMax:
value = baseAbility.getHpmax();
break;
case Hit:
value = baseAbility.getHit();
break;
case Initiative:
value = baseAbility.getInitiative();
break;
case Intelligence:
value = baseAbility.getIntelligence();
break;
case MCharmdel:
value = baseAbility.getMcharmdel();
break;
case MCmax:
case MCmin:
value = RandomUtils.random(baseAbility.getMcmin(), baseAbility.getMcmax());
break;
case Mac:
case MacCount:
value = baseAbility.getMac();
break;
case MpMax:
value = baseAbility.getMpmax();
break;
case Strength:
value = baseAbility.getStrength();
break;
case Speed:
case SpeedCount:
value = baseAbility.getSpeed();
break;
case Toughness:
value = baseAbility.getToughness();
break;
case UnDCharmdel:
value = baseAbility.getUndcharmdel();
break;
case UnMCharmdel:
value = baseAbility.getUnmcharmdel();
break;
case Willpower:
value = baseAbility.getWillpower();
break;
case Wounds:
value = baseAbility.getWounds();
break;
}
return value;
}

/**
* 构建属性
* <br>
* 慎重调用
*
* @param baseAbility
*/
@Deprecated
public void buildBaseAbility(BaseAbility baseAbility) {
baseAbility.setExpmax(baseAbility.getExpmax() + this.getExpMax());
for (Entry<AttKey, Integer> entry : this.entrySet()) {
AttKey key = entry.getKey();
Integer value = entry.getValue();
switch (key) {
case AC:
case ACCount:
baseAbility.setAc(baseAbility.getAc() + value);
break;
case AttackSpeed:
baseAbility.setAttackSpeed(baseAbility.getAttackSpeed() + value);
break;
case AutoBattleHP:
baseAbility.setAuto_battle_hp(baseAbility.getAuto_battle_hp() + value);
break;
case AutoBattleMP:
baseAbility.setAuto_battle_mp(baseAbility.getAuto_battle_mp() + value);
break;
case AutoHP:
baseAbility.setAutohp(baseAbility.getAutohp() + value);
break;
case AutoMP:
baseAbility.setAutomp(baseAbility.getAutomp() + value);
break;
case CritValue:
baseAbility.setCritvalue(baseAbility.getCritvalue() + value);
break;
case CritValuePer:
baseAbility.setCritValuePer(baseAbility.getCritValuePer() + value);
break;
case DCcount:
baseAbility.setDcmin(baseAbility.getDcmin() + value);
baseAbility.setDcmax(baseAbility.getDcmax() + value);
break;
case DCharmdel:
baseAbility.setDcharmdel(baseAbility.getDcharmdel() + value);
break;
case DCmax:
baseAbility.setDcmax(baseAbility.getDcmax() + value);
break;
case DCmin:
baseAbility.setDcmin(baseAbility.getDcmin() + value);
break;
case Dcuk:
baseAbility.setDuck(baseAbility.getDuck() + value);
break;
case Fight:
baseAbility.setFight(baseAbility.getFight() + value);
break;
case HPMax:
baseAbility.setHpmax(baseAbility.getHpmax() + value);
break;
case Hit:
baseAbility.setHit(baseAbility.getHit() + value);
break;
case Initiative:
baseAbility.setInitiative(baseAbility.getInitiative() + value);
break;
case Intelligence:
baseAbility.setIntelligence(baseAbility.getIntelligence() + value);
break;
case MCcount:
baseAbility.setMcmin(baseAbility.getMcmin() + value);
baseAbility.setMcmax(baseAbility.getMcmax() + value);
break;
case MCharmdel:
baseAbility.setMcharmdel(baseAbility.getMcharmdel() + value);
break;
case MCmax:
baseAbility.setMcmax(baseAbility.getMcmax() + value);
break;
case MCmin:
baseAbility.setMcmin(baseAbility.getMcmin() + value);
break;
case Mac:
case MacCount:
baseAbility.setMac(baseAbility.getMac() + value);
break;
case MpMax:
baseAbility.setMpmax(baseAbility.getMpmax() + value);
break;
case Strength:
baseAbility.setStrength(baseAbility.getStrength() + value);
break;
case Speed:
case SpeedCount:
baseAbility.setSpeed(baseAbility.getSpeed() + value);
break;
case Toughness:
baseAbility.setToughness(baseAbility.getToughness() + value);
break;
case UnDCharmdel:
baseAbility.setUndcharmdel(baseAbility.getUndcharmdel() + value);
break;
case UnMCharmdel:
baseAbility.setUnmcharmdel(baseAbility.getUnmcharmdel() + value);
break;
case Willpower:
baseAbility.setWillpower(baseAbility.getWillpower() + value);
break;
case Wounds:
baseAbility.setWounds(baseAbility.getWounds() + value);
break;
}
}
}

/**
* 构建属性,构建属性集合中比例属性加成,万分比格式
* <br>
* 慎重调用
*
* @param baseAbility
*/
@Deprecated
public void buildBaseAbilityPer(BaseAbility baseAbility) {
for (Entry<AttKey, Integer> entry : this.entrySet()) {
AttKey key = entry.getKey();
Integer value = entry.getValue();
switch (key) {
case ACPer:
baseAbility.setAc(baseAbility.getAc() + (int) (baseAbility.getAc() * (value / 10000D)));
break;
case DCper:
baseAbility.setDcmin(baseAbility.getDcmin() + (int) (baseAbility.getDcmin() * (value / 10000D)));
baseAbility.setDcmax(baseAbility.getDcmax() + (int) (baseAbility.getDcmax() * (value / 10000D)));
break;
case HPMaxper:
baseAbility.setHpmax(baseAbility.getHpmax() + (int) (baseAbility.getHpmax() * (value / 10000D)));
break;
case MCper:
baseAbility.setMcmin(baseAbility.getMcmin() + (int) (baseAbility.getMcmin() * (value / 10000D)));
baseAbility.setMcmax(baseAbility.getMcmax() + (int) (baseAbility.getMcmax() * (value / 10000D)));
break;
case MacPer:
baseAbility.setMac(baseAbility.getMac() + (int) (baseAbility.getMac() * (value / 10000D)));
break;
case SpeedPer:
baseAbility.setSpeed(baseAbility.getSpeed() + (int) (baseAbility.getSpeed() * (value / 10000D)));
break;
}
}
}

@Override
public String toString() {
for (Entry<AttKey, Integer> entry : this.entrySet()) {
AttKey key = entry.getKey();
Integer value = entry.getValue();
}
return "PlayerAttribute{" + '}';
}

/**
* 所有属性清零
*/
public void clearZoer() {
for (Entry<AttKey, Integer> entry : this.entrySet()) {
AttKey key = entry.getKey();
Integer value = entry.getValue();
this.put(key, 0);
}
}

/**
* 累计
*
* @param playerAttribute
*/
public void add(PersonAttribute playerAttribute) {
for (Entry<AttKey, Integer> entry : playerAttribute.entrySet()) {
AttKey key = entry.getKey();
Integer value = entry.getValue();
Integer get = this.get(key);
value += get;
this.put(key, value);
}
this.expMax += playerAttribute.expMax;
}

/**
*
* @param key
* @param value
*/
public void add(int key, Integer value) {
add(AttKey.parse(key), value);
}

/**
*
* @param key
* @param value
*/
public void add(AttKey key, Integer value) {
if (key != null) {
Integer get = this.get(key);
value += get;
this.put(key, value);
}
}

public Long getExpMax() {
return expMax;
}

public void setExpMax(Long expMax) {
this.expMax = expMax;
}

public static void main(String[] args) {
String toString = PersonAttribute.AttKey.Initiative.toString();
System.out.println(toString);
System.out.println(PersonAttribute.AttKey.parse(toString).getValue());
}
}

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

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

// <editor-fold defaultstate="collapsed" desc="返回属性键值对 public static void getAttribute(PersonAttribute attribute, String attString)">
/**
* 返回属性键值对
*
* @param attribute
* @param attString 配置的属性
*/
public static void getAttribute(PersonAttribute attribute, String attString) {
if (StringUtil.isNullOrEmpty(attString)) {
return;
}
String[] atts = attString.split(DOUHAO_REG);
for (String att : atts) {
String[] split = att.split("=");
Integer integer = Integer.parseInt(split[0]);
Integer integer1 = Integer.parseInt(split[1]);
attribute.add(integer, integer1);
}
}
// </editor-fold>

public static void main(String[] args) {
String str = "34052=792,34050=1291,34051=3";
PersonAttribute personAttribute = new PersonAttribute();
getAttribute(personAttribute, str);
}

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

// 属性
//最终计算属性
protected BaseAbility finalAbility = new BaseAbility();

//-------------------属性部分-------------------------//
private /*transient这样可能会导致离线竞技场角色数据不正确*/ HashMap<Integer, PersonAttribute> attributes = new HashMap<>();
//其他属性
protected PersonAttribute otherAttribute = new PersonAttribute();

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

@Override
public void computeAttribute(Player player, boolean updateTopListFightPower) {
synchronized (player.abilityLock) {
player.abilityLock.update();

PersonAttribute finalAbility = new PersonAttribute();

HashMap<Integer, PersonAttribute> attributes = player.getAttributes();
//先把非buff的属性计算完成
for (Map.Entry<Integer, PersonAttribute> entry : attributes.entrySet()) {
Integer key = entry.getKey();
if (key != PersonAttributeType.BUFF) {
PersonAttribute playerAttribute = entry.getValue();
if (playerAttribute != null) {
finalAbility.add(playerAttribute);
}
}
}
player.getFinalAbility().clearZero();
//构建基础属性
finalAbility.buildBaseAbility(player.getFinalAbility());
finalAbility.buildBaseAbilityPer(player.getFinalAbility());

//清零后计算buff
finalAbility.clear();

//再计算buff的属性计算完成
for (Map.Entry<Integer, PersonAttribute> entry : attributes.entrySet()) {
Integer key = entry.getKey();
if (key == PersonAttributeType.BUFF) {
PersonAttribute playerAttribute = entry.getValue();
if (playerAttribute != null) {
finalAbility.add(playerAttribute);
}
}
}
//构建基础属性
//先计算buff加成
finalAbility.buildBaseAbilityPer(player.getFinalAbility());
//在计算buff基础点数
finalAbility.buildBaseAbility(player.getFinalAbility());
//设置经验比例加成
player.setExpMultiple(1 + finalAbility.get(PersonAttribute.AttKey.ExpPer)); // 特殊处理经验BUFF经验BUFF
player.getFinalAbility().zeroAbility();
log.error("当前速度:" + player.getFinalAbility().getSpeed());
{
//属性,加成
//物理攻击加成
player.getFinalAbility().setDcmin(player.getFinalAbility().getDcmin() + player.getFinalAbility().getStrength());
player.getFinalAbility().setDcmax(player.getFinalAbility().getDcmax() + player.getFinalAbility().getStrength());
//物理防御
player.getFinalAbility().setAc(player.getFinalAbility().getAc() + player.getFinalAbility().getStrength());
//生命上限
player.getFinalAbility().setHpmax(player.getFinalAbility().getHpmax() + player.getFinalAbility().getWounds() * 8);
//魔法攻击
player.getFinalAbility().setMcmin(player.getFinalAbility().getMcmin() + player.getFinalAbility().getIntelligence());
player.getFinalAbility().setMcmax(player.getFinalAbility().getMcmax() + player.getFinalAbility().getIntelligence());
//魔法防御
player.getFinalAbility().setMac(player.getFinalAbility().getMac() + player.getFinalAbility().getIntelligence());
//魔法值上限
player.getFinalAbility().setMpmax(player.getFinalAbility().getMpmax() + player.getFinalAbility().getIntelligence() * 6);
//闪避
player.getFinalAbility().setDuck(player.getFinalAbility().getDuck() + player.getFinalAbility().getInitiative());
//韧性
player.getFinalAbility().setToughness(player.getFinalAbility().getToughness() + (int) (player.getFinalAbility().getInitiative() * 0.5));
//命中
player.getFinalAbility().setHit(player.getFinalAbility().getHit() + (int) (player.getFinalAbility().getWillpower() * 0.5));
//暴击
player.getFinalAbility().setCritValuePer(player.getFinalAbility().getCritValuePer() + (int) (player.getFinalAbility().getWillpower()));

}

if (updateTopListFightPower && !player.isArenaRobot() && player.getLevel() >= TopListManager.SYNC_PLAYER_LEVEL) { // 如BUFF等改变玩家属性,将不触发排行榜
//                log.error("玩家战斗力改变,触发战力排行榜");
TopListManager.getInstance().updateAllTopData(player, null, TopListManager.TOP_POWER);
}
}
}

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

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

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐