Example #1
0
//创建一个技能项
func NewSkillItem(parent *Skill, plugStep Step, chooser targetChoose.TargetChooser, probability float64) *SkillItem {
	return &SkillItem{
		Probability: attribute.NewAttribute("Probability", "技能释放概率", probability),
		SkillParent: parent,
		PluginStep:  plugStep,
		Chooser:     chooser,
		EffectItems: make([]effect.Effect, 0),
	}
}
Example #2
0
func GetCharacter() *character.Character {
	seed_character++

	ch1 := character.NewCharacter("id"+strconv.FormatInt(int64(seed_character), 10), "giveName"+strconv.FormatInt(int64(seed_character), 10), "familyName"+strconv.FormatInt(int64(seed_character), 10), nil)
	//设置基本属性
	ch1.SetAttr(attribute.NewAttribute(attribute.AGI, "敏捷", 10))
	ch1.SetAttr(attribute.NewAttribute(attribute.STR, "力量", 10))
	ch1.SetAttr(attribute.NewAttribute(attribute.INT, "智力", 10))
	ch1.SetAttr(attribute.NewAttribute(attribute.VIT, "体力", 10))
	ch1.SetAttr(attribute.NewAttribute(attribute.LUCK, "运气", 10))
	ch1.SetAttr(attribute.NewAttribute(attribute.AWARE, "感知", 10))
	ch1.SetAttr(attribute.NewAttribute(attribute.UNDERSTAND, "悟性", 10))
	return ch1
}
Example #3
0
//配置修正值
//每次调用config,都相当于添加1或n个属性,属性参数一字排开
//例子:Config("STR","力量",10,"AGI","敏捷",20,...)
func (self *AttributeModify) Config(args ...interface{}) {
	if len(args) > 0 {
		name := ""
		desc := ""
		raw := 0.0
		for i := 0; i < len(args); i++ {
			switch i % 3 {
			case 0:
				name = args[i].(string) //参数0:属性名
			case 1:
				desc = args[i].(string) //参数1:属性描述
			case 2:
				raw = args[i].(float64) //参数2:属性原始值

				//写入效果的属性列表(如果重复存在,第一次写入的为准)
				self.AddAttr(attribute.NewAttribute(name, desc, raw))
			}
		}
	}
}
func main() {
	builtIn.RegBuiltInEffects()
	buildInChoosers.RegBuiltInChoosers()
	//创建2个角色
	ch1 := character.NewCharacter("id1", "giveName1", "familyName1", nil)
	ch2 := character.NewCharacter("id2", "giveName2", "familyName2", nil)

	attackChooser := targetChoose.Create("ChooseByWeak")
	attackChooser.Config(1) //选择攻击范围里1个人
	//设置基本属性
	ch1.SetAttr(attribute.NewAttribute(attribute.AGI, "敏捷", 10))
	ch1.SetAttr(attribute.NewAttribute(attribute.STR, "力量", 10))
	ch1.SetAttr(attribute.NewAttribute(attribute.INT, "智力", 10))
	ch1.SetAttr(attribute.NewAttribute(attribute.VIT, "体力", 10))
	ch1.SetAttr(attribute.NewAttribute(attribute.LUCK, "运气", 10))
	ch1.SetAttr(attribute.NewAttribute(attribute.AWARE, "感知", 10))
	ch1.SetAttr(attribute.NewAttribute(attribute.UNDERSTAND, "悟性", 10))

	warrior1 := battle.NewWarrior(ch1, nature.Physical, attackChooser, 12, 0, 200, 30, 200, 20, 12, 30)

	ch2.SetAttr(attribute.NewAttribute(attribute.AGI, "敏捷", 10))
	ch2.SetAttr(attribute.NewAttribute(attribute.STR, "力量", 10))
	ch2.SetAttr(attribute.NewAttribute(attribute.INT, "智力", 10))
	ch2.SetAttr(attribute.NewAttribute(attribute.VIT, "体力", 10))
	ch2.SetAttr(attribute.NewAttribute(attribute.LUCK, "运气", 10))
	ch2.SetAttr(attribute.NewAttribute(attribute.AWARE, "感知", 10))
	ch2.SetAttr(attribute.NewAttribute(attribute.UNDERSTAND, "悟性", 10))

	warrior2 := battle.NewWarrior(ch2, nature.Physical, attackChooser, 12, 0, 200, 30, 200, 20, 12, 30)

	//创建一个效果
	modifyEffect := effect.Create("AttributeModify")

	//配置该效果要修正的属性值
	modifyEffect.Config(attribute.STR, "力量", -20.0)

	//模拟场景:角色1给角色2添加减力量效果
	modifyEffect.PutOn(warrior1, warrior2)

	//检查属性,看减力量效果是否生效
	if warrior2.GetAttr(attribute.STR).GetValue().Get() != -10 {
		panic(fmt.Sprintf("str must be -10,but now is %v", warrior2.GetAttr(attribute.STR).GetValue().Get()))
	}

	//添加一个抵抗减属性的 效果
	decResistanceEffect := effect.Create("AttributeDecResistance")
	//所有减属性类的效果,全部抵抗10
	decResistanceEffect.Config(10.0)
	//安装效果
	decResistanceEffect.PutOn(warrior1, warrior2)
	fmt.Printf(" 1.1 看减力量效果是否生效:all attr is: %v \n", warrior2.GetAllAttr())
	//检查属性,应该有变化
	if warrior2.GetAttr(attribute.STR).GetValue().Get() != 0 {
		panic(fmt.Sprintf("str must be 0,but now is %v", warrior2.GetAttr(attribute.STR).GetValue().Get()))
	}

	//todo:1.2 -- 再添加一个削弱效果少一点的效果,测试技能抵抗不能变成加成
	modifyEffect2 := effect.Create("AttributeModify")

	//智力-5,小于抵抗值,测试抵抗效果的修正
	modifyEffect2.Config(attribute.INT, "智力", -5.0)

	//模拟场景:角色1给角色2添加减力量效果
	modifyEffect2.PutOn(warrior1, warrior2)
	fmt.Printf(" 1.2 再添加一个削弱效果少一点的效果:all attr is: %v \n", warrior2.GetAllAttr())
	//检查属性,应该没有变化(被抵抗了)
	if warrior2.GetAttr(attribute.INT).GetValue().Get() != 10 {
		panic(fmt.Sprintf("INT must be 10,but now is %v", warrior2.GetAttr(attribute.INT).GetValue().Get()))
	}

	//todo:2 -- 移除抵抗效果,看什么情况
	decResistanceEffect.Remove()
	fmt.Printf(" 2.1 移除抵抗效果:all attr is: %v \n", warrior2.GetAllAttr())
	//检查属性被影响
	if warrior2.GetAttr(attribute.STR).GetValue().Get() != -10 {
		panic(fmt.Sprintf("str must be -10,but now is %v", warrior2.GetAttr(attribute.STR).GetValue().Get()))
	}
	if warrior2.GetAttr(attribute.INT).GetValue().Get() != 5 {
		panic(fmt.Sprintf("INT must be 5,but now is %v", warrior2.GetAttr(attribute.INT).GetValue().Get()))
	}

	//todo:3 -- 移除属性加成效果,看什么情况
	modifyEffect.Remove()
	fmt.Printf(" 3.1 移除抵抗效果 modifyEffect:all attr is: %v \n", warrior2.GetAllAttr())
	if warrior2.GetAttr(attribute.STR).GetValue().Get() != 10 {
		panic(fmt.Sprintf("str must be 10,but now is %v", warrior2.GetAttr(attribute.STR).GetValue().Get()))
	}
	if warrior2.GetAttr(attribute.INT).GetValue().Get() != 5 {
		panic(fmt.Sprintf("INT must be 5,but now is %v", warrior2.GetAttr(attribute.INT).GetValue().Get()))
	}
	modifyEffect2.Remove()
	fmt.Printf(" 3.2 移除抵抗效果 modifyEffect2:all attr is: %v \n", warrior2.GetAllAttr())
	if warrior2.GetAttr(attribute.STR).GetValue().Get() != 10 {
		panic(fmt.Sprintf("str must be 10,but now is %v", warrior2.GetAttr(attribute.STR).GetValue().Get()))
	}
	if warrior2.GetAttr(attribute.INT).GetValue().Get() != 10 {
		panic(fmt.Sprintf("INT must be 10,but now is %v", warrior2.GetAttr(attribute.INT).GetValue().Get()))
	}
}
Example #5
0
func main() {
	buildInEffect.RegBuiltInEffects()
	buildInChoosers.RegBuiltInChoosers()

	attackChooser := targetChoose.Create("ChooseByWeak")
	attackChooser.Config(1) //选择攻击范围里1个人

	//创建2个角色
	ch1 := character.NewCharacter("id1", "giveName1", "familyName1", nil)
	ch2 := character.NewCharacter("id2", "giveName2", "familyName2", nil)

	//设置基本属性
	ch1.SetAttr(attribute.NewAttribute(attribute.AGI, "敏捷", 10))
	ch1.SetAttr(attribute.NewAttribute(attribute.STR, "力量", 10))
	ch1.SetAttr(attribute.NewAttribute(attribute.INT, "智力", 10))
	ch1.SetAttr(attribute.NewAttribute(attribute.VIT, "体力", 10))
	ch1.SetAttr(attribute.NewAttribute(attribute.LUCK, "运气", 10))
	ch1.SetAttr(attribute.NewAttribute(attribute.AWARE, "感知", 10))
	ch1.SetAttr(attribute.NewAttribute(attribute.UNDERSTAND, "悟性", 10))

	warrior1 := battle.NewWarrior(ch1, nature.Physical, attackChooser, 12, 0, 200, 30, 200, 20, 12, 30)

	ch2.SetAttr(attribute.NewAttribute(attribute.AGI, "敏捷", 10))
	ch2.SetAttr(attribute.NewAttribute(attribute.STR, "力量", 10))
	ch2.SetAttr(attribute.NewAttribute(attribute.INT, "智力", 10))
	ch2.SetAttr(attribute.NewAttribute(attribute.VIT, "体力", 10))
	ch2.SetAttr(attribute.NewAttribute(attribute.LUCK, "运气", 10))
	ch2.SetAttr(attribute.NewAttribute(attribute.AWARE, "感知", 10))
	ch2.SetAttr(attribute.NewAttribute(attribute.UNDERSTAND, "悟性", 10))

	warrior2 := battle.NewWarrior(ch2, nature.Physical, attackChooser, 12, 0, 200, 30, 200, 20, 12, 30)

	//创建一个效果
	modifyEffect := effect.Create("AttributeModify")

	//配置该效果要修正的属性值
	modifyEffect.Config(attribute.STR, "力量", 20.0)
	//给角色2添加效果
	modifyEffect.PutOn(warrior1, warrior2)

	//检查属性
	if warrior2.GetAttr(attribute.STR).GetValue().Get() != 30 {
		panic(fmt.Sprintf("str must be 30,but now is %v", warrior2.GetAttr(attribute.STR).GetValue().Get()))
	}
	fmt.Printf("all attr is: %v \n", warrior2.GetAllAttr())
	fmt.Printf("warrior2 is: %v \n", warrior2)

	fmt.Printf("remove effect!---------- \n")
	//移除效果
	modifyEffect.Remove()

	//检查属性
	if warrior2.GetAttr(attribute.STR).GetValue().Get() != 10 {
		panic(fmt.Sprintf("str must be 10,but now is %v", warrior2.GetAttr(attribute.STR).GetValue().Get()))
	}
	fmt.Printf("all attr is: %v \n", warrior2.GetAllAttr())
	fmt.Printf("warrior2 is: %v \n", warrior2)

}
Example #6
0
//创建一个战斗角色
func NewWarrior(character *character.Character, normalAttackNature nature.Nature, normalAttackChooser targetChoose.TargetChooser, size, attackFrom, attackTo, op, hp, ap, eachOpMoveDistance, maxAp float64) *Warrior {
	w := &Warrior{
		Character:           character,
		Status:              WARRIOR_INACTIVE,
		Size:                attribute.NewAttribute("size", "大小", size),
		NormalAttackSection: dataStructure.NewSection("attackSection", "攻击范围", attackFrom, attackTo),
		NormalAttackNature:  normalAttackNature,
		NormalAttackChooser: normalAttackChooser,
		EachOpMoveDistance:  attribute.NewAttribute("EachOpMoveDistance", "每一个Op可以移动的距离长度", eachOpMoveDistance),
		//		OP:attribute.NewAttribute("OP","当前行动点数",op),
		//		HP:attribute.NewAttribute("HP","当前Hp",hp),
		//		AP:attribute.NewAttribute("AP","当前怒气",ap),
		MaxAP: attribute.NewAttribute("MaxAP", "最大怒气", maxAp),
	}
	allAttr := w.Character.GetAllAttr()
	AGI := allAttr[attribute.AGI]
	AWARE := allAttr[attribute.AWARE]
	STR := allAttr[attribute.STR]
	VIT := allAttr[attribute.VIT]
	INT := allAttr[attribute.INT]
	LUCK := allAttr[attribute.LUCK]
	//	UNDERSTAND := allAttr[attribute.UNDERSTAND]
	//计算属性:行动顺序
	w.ActSeq = attribute.NewComputedAttribute("ActSeq", "行动顺序", 0,
		func(dependencies ...attribute.AttributeLike) float64 {
			base := 50.0
			agi := dependencies[0].GetValue().Get()
			aware := dependencies[1].GetValue().Get()
			return base + (3*agi + 5.3*math.Floor(agi/7)) - (0.2*aware + 0.5*math.Floor(aware/9))
		}, AGI, AWARE)

	//计算属性:最大行动点数
	w.MaxOp = attribute.NewComputedAttribute("MaxOp", "最大行动点数", 0,
		func(dependencies ...attribute.AttributeLike) float64 {
			base := 128.0
			agi := dependencies[0].GetValue().Get()
			vit := dependencies[1].GetValue().Get()
			return base + math.Floor(agi/3) + math.Floor(vit/9)
		}, AGI, VIT)

	//计算属性:行动点数恢复速度(每秒)
	w.OPRecover = attribute.NewComputedAttribute("OPRecover", "行动点数恢复速度", 0,
		func(dependencies ...attribute.AttributeLike) float64 {
			base := 28.0
			agi := dependencies[0].GetValue().Get()
			vit := dependencies[1].GetValue().Get()
			return base + (0.6 * math.Floor(agi/3)) + (0.2 * math.Floor(vit/5))
		}, AGI, VIT)

	w.OP = attribute.NewRegeneratedAttribute("OP", "当前行动点数", op, w.MaxOp.GetValue(), w.OPRecover.GetValue(), 1*time.Second)

	//计算属性:普通攻击\技能等动作,需要消耗的Op数量
	w.EachActionCostOP = attribute.NewComputedAttribute("EachActionCostOP", "动作消耗的Op数量", 0,
		func(dependencies ...attribute.AttributeLike) float64 {
			base := 128.0
			//			base := 32.0
			agi := dependencies[0].GetValue().Get()
			return base - math.Floor(agi/50)
		}, AGI)
	//计算属性:物理攻击力
	w.AttackPhysical = attribute.NewComputedAttribute("AttackPhysical", "物理攻击力", 0,
		func(dependencies ...attribute.AttributeLike) float64 {
			str := dependencies[0].GetValue().Get()
			vit := dependencies[1].GetValue().Get()
			return (str + 11*math.Floor(str/9)) + (0.3*vit + 2*math.Floor(vit/8))
		}, STR, VIT)
	//计算属性:魔法攻击力
	w.AttackMagical = attribute.NewComputedAttribute("AttackMagical", "魔法攻击力", 0,
		func(dependencies ...attribute.AttributeLike) float64 {
			intel := dependencies[0].GetValue().Get()
			vit := dependencies[1].GetValue().Get()
			return (intel + 9*math.Floor(intel/7)) + (0.3*vit + 2*math.Floor(vit/8))
		}, INT, VIT)
	//计算属性:物理暴击率
	w.CriticalRatePhysical = attribute.NewComputedAttribute("CriticalRatePhysical", "物理暴击率", 0,
		func(dependencies ...attribute.AttributeLike) float64 {
			base := 0.15
			str := dependencies[0].GetValue().Get()
			agi := dependencies[1].GetValue().Get()
			vit := dependencies[2].GetValue().Get()
			luk := dependencies[3].GetValue().Get()
			aware := dependencies[4].GetValue().Get()

			return base + (0.02 * math.Floor(luk/3)) + (0.01 * math.Floor(aware/5)) + (0.01 * math.Floor((str-agi+vit)/30))
		}, STR, AGI, VIT, LUCK, AWARE)

	//计算属性:魔法暴击率
	w.CriticalRateMagical = attribute.NewComputedAttribute("CriticalRateMagical", "魔法暴击率", 0,
		func(dependencies ...attribute.AttributeLike) float64 {
			base := 0.15
			intel := dependencies[0].GetValue().Get()
			luk := dependencies[1].GetValue().Get()
			aware := dependencies[2].GetValue().Get()

			return base + (0.02 * math.Floor(luk/3)) + (0.01 * math.Floor(aware/5)) + (0.01 * math.Floor(intel/7))
		}, INT, LUCK, AWARE)

	//计算属性:物理防御力
	w.DefencePhysical = attribute.NewComputedAttribute("DefencePhysical", "物理防御力", 0,
		func(dependencies ...attribute.AttributeLike) float64 {
			str := dependencies[0].GetValue().Get()
			vit := dependencies[1].GetValue().Get()
			aware := dependencies[2].GetValue().Get()

			return (math.Floor((str + aware) / 4)) + (vit + 1.3*math.Floor(vit/3))
		}, STR, VIT, AWARE)
	//计算属性:魔法防御力
	w.DefenceMagical = attribute.NewComputedAttribute("DefenceMagical", "魔法防御力", 0,
		func(dependencies ...attribute.AttributeLike) float64 {
			intel := dependencies[0].GetValue().Get()
			vit := dependencies[1].GetValue().Get()
			aware := dependencies[2].GetValue().Get()

			return 0.3*vit + 2.3*math.Floor((intel+vit+aware)/4)
		}, INT, VIT, AWARE)
	//计算属性:物理闪避率
	w.FleeRatePhysical = attribute.NewComputedAttribute("FleeRatePhysical", "物理闪避率", 0,
		func(dependencies ...attribute.AttributeLike) float64 {
			base := 0.05
			str := dependencies[0].GetValue().Get()
			vit := dependencies[1].GetValue().Get()
			agi := dependencies[2].GetValue().Get()
			luk := dependencies[3].GetValue().Get()
			aware := dependencies[4].GetValue().Get()

			return base + (0.01 * math.Floor((agi+luk)/4)) + (0.01 * math.Floor(aware/5)) - (0.01 * math.Floor((str+vit)/15))
		}, STR, VIT, AGI, LUCK, AWARE)

	//计算属性:魔法闪避率
	w.FleeRateMagical = attribute.NewComputedAttribute("FleeRateMagical", "魔法闪避率", 0,
		func(dependencies ...attribute.AttributeLike) float64 {
			base := 0.05
			agi := dependencies[0].GetValue().Get()
			intel := dependencies[1].GetValue().Get()
			luk := dependencies[2].GetValue().Get()
			aware := dependencies[3].GetValue().Get()

			return base + (0.01*math.Floor((luk/4)) + (0.01 * math.Floor((agi+intel+aware)/15)))
		}, AGI, INT, LUCK, AWARE)
	//计算属性:物理命中率
	w.HitRatePhysical = attribute.NewComputedAttribute("HitRatePhysical", "物理命中率", 0,
		func(dependencies ...attribute.AttributeLike) float64 {
			base := 1.0
			luk := dependencies[0].GetValue().Get()
			aware := dependencies[1].GetValue().Get()

			return base + (0.01 * math.Floor((aware+luk)/4))
		}, LUCK, AWARE)

	//计算属性:魔法命中率
	w.HitRateMagical = attribute.NewComputedAttribute("HitRateMagical", "魔法命中率", 0,
		func(dependencies ...attribute.AttributeLike) float64 {
			base := 1.0
			luk := dependencies[0].GetValue().Get()
			intel := dependencies[1].GetValue().Get()

			return base + (0.01 * math.Floor((intel+luk)/4))
		}, LUCK, INT)

	//计算属性:最大生命值
	w.MaxHp = attribute.NewComputedAttribute("MaxHp", "最大生命值", 0,
		func(dependencies ...attribute.AttributeLike) float64 {
			base := 120.0
			str := dependencies[0].GetValue().Get()
			vit := dependencies[1].GetValue().Get()
			intel := dependencies[2].GetValue().Get()

			return base + str + vit + (23 * math.Floor(vit/3)) - 3*math.Floor(intel/3)
		}, STR, VIT, INT)

	//计算属性:生命值回复(每秒)
	w.HpRecover = attribute.NewComputedAttribute("HpRecover", "生命值回复", 0,
		func(dependencies ...attribute.AttributeLike) float64 {
			base := 0.4
			vit := dependencies[0].GetValue().Get()

			return base + 0.01*vit + (0.02 * math.Floor(vit/5))
		}, VIT)

	w.HP = attribute.NewRegeneratedAttribute("HP", "当前Hp", hp, w.MaxHp.GetValue(), w.HpRecover.GetValue(), 1*time.Second)

	//计算属性:怒气值回复(每秒)
	w.ApRecover = attribute.NewComputedAttribute("ApRecover", "怒气值回复", 0,
		func(dependencies ...attribute.AttributeLike) float64 {
			base := 0.1
			aware := dependencies[0].GetValue().Get()

			return base + 0.05*aware + (0.25 * math.Floor(aware/7))
		}, AWARE)
	w.AP = attribute.NewRegeneratedAttribute("AP", "当前怒气", ap, w.MaxAP.GetValue(), w.ApRecover.GetValue(), 1*time.Second)
	return w
}
Example #7
0
func NewSection(name, desc string, from, to float64) *Section {
	return &Section{
		From: attribute.NewAttribute(name+"-from", desc+"起", from),
		To:   attribute.NewAttribute(name+"-to", desc+"止", to),
	}
}