mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-06-05 11:17:13 +08:00
refactor(MathTool): 重命名随机数相关方法以提高可读性
将 randv2_range 重命名为 randomVector2In,randc_from 重命名为 randomChoiceFrom,randc_from_weights 重命名为 randChoiceWeightsFrom,并新增 randomRingPoint 方法
This commit is contained in:
@@ -17,5 +17,5 @@ static func distanceAction(entity: EntityBase, target: EntityBase, minDistance:
|
||||
if minDistance <= distance and distance <= maxDistance:
|
||||
action.call()
|
||||
static func weightAttack(entity: EntityBase, indexes: Array[int], weight: Array[int], chargeUp: Callable):
|
||||
var method = MathTool.randc_from_weights(indexes, weight)
|
||||
var method = MathTool.randChoiceWeightsFrom(indexes, weight)
|
||||
entity.tryAttack(method, chargeUp.call(method))
|
||||
|
||||
@@ -8,7 +8,7 @@ func succeedToHit(_dmg, entity):
|
||||
if MathTool.rate(rate):
|
||||
for i in randi_range(1, count):
|
||||
ItemDropped.generate(
|
||||
MathTool.randc_from([ItemStore.ItemType.BASEBALL, ItemStore.ItemType.BASKETBALL, ItemStore.ItemType.BEACHBALL]),
|
||||
MathTool.randomChoiceFrom([ItemStore.ItemType.BASEBALL, ItemStore.ItemType.BASKETBALL, ItemStore.ItemType.BEACHBALL]),
|
||||
randi_range(1, count),
|
||||
entity.position + MathTool.randv2_range(GameRule.itemDroppedSpawnOffset)
|
||||
entity.position + MathTool.randomVector2In(GameRule.itemDroppedSpawnOffset)
|
||||
)
|
||||
|
||||
@@ -52,11 +52,11 @@ func attack(type):
|
||||
if !is_instance_valid(currentFocusedBoss): return false
|
||||
for bullet in BulletBase.generate(ComponentManager.getBullet("ArrowSeven"), self, findWeaponAnchor("normal"), deg_to_rad(randf_range(0, 360))):
|
||||
bullet.tracer = currentFocusedBoss
|
||||
bullet.position += MathTool.randv2_range(50)
|
||||
bullet.position += MathTool.randomVector2In(50)
|
||||
await TickTool.millseconds(50)
|
||||
return false
|
||||
elif type == 1:
|
||||
await sprintTo(currentFocusedBoss.position - Vector2(MathTool.randc_from([-300, 300]), 300), 0.25)
|
||||
await sprintTo(currentFocusedBoss.position - Vector2(MathTool.randomChoiceFrom([-300, 300]), 300), 0.25)
|
||||
var count = randi_range(6, 8)
|
||||
for i in range(count):
|
||||
BulletBase.generate(ComponentManager.getBullet("SunDance"), self, weaponPos, deg_to_rad(360.0 / count * i))
|
||||
@@ -66,7 +66,7 @@ func attack(type):
|
||||
bullet.rotation = 360 / 13.0 * i
|
||||
elif type == 3:
|
||||
if !is_instance_valid(currentFocusedBoss): return false
|
||||
await sprintTo(currentFocusedBoss.position - Vector2(MathTool.randc_from([500, -500]), 0), 0.25)
|
||||
await sprintTo(currentFocusedBoss.position - Vector2(MathTool.randomChoiceFrom([500, -500]), 0), 0.25)
|
||||
sprintParticle.emitting = true
|
||||
canRunAi = false
|
||||
currentInvinsible = true
|
||||
@@ -76,7 +76,7 @@ func attack(type):
|
||||
await trySprint()
|
||||
sprintParticle.emitting = false
|
||||
canRunAi = true
|
||||
await sprintTo(currentFocusedBoss.position + MathTool.randv2_range(400), 0.25)
|
||||
await sprintTo(currentFocusedBoss.position + MathTool.randomVector2In(400), 0.25)
|
||||
currentInvinsible = false
|
||||
return false
|
||||
elif type == 4:
|
||||
@@ -102,8 +102,8 @@ func attack(type):
|
||||
for i in 16:
|
||||
if !is_instance_valid(currentFocusedBoss): return false
|
||||
for bullet in BulletBase.generate(ComponentManager.getBullet("LightGun"), self, currentFocusedBoss.position, 0):
|
||||
bullet.position += MathTool.randv2_range(600)
|
||||
bullet.look_at(currentFocusedBoss.position + MathTool.randv2_range(50))
|
||||
bullet.position += MathTool.randomVector2In(600)
|
||||
bullet.look_at(currentFocusedBoss.position + MathTool.randomVector2In(50))
|
||||
await TickTool.millseconds(100)
|
||||
return false
|
||||
elif type == 7:
|
||||
|
||||
@@ -34,7 +34,7 @@ func attack(type):
|
||||
if type == 0:
|
||||
var weaponPos = findWeaponAnchor("normal")
|
||||
for i in randi_range(7, 16):
|
||||
BulletBase.generate(ComponentManager.getBullet("Diamond"), self, weaponPos + MathTool.randv2_range(20), rotation + deg_to_rad(randf_range(-90, 90)))
|
||||
BulletBase.generate(ComponentManager.getBullet("Diamond"), self, weaponPos + MathTool.randomVector2In(20), rotation + deg_to_rad(randf_range(-90, 90)))
|
||||
elif type == 1:
|
||||
var laserCount = randi_range(2, 4)
|
||||
for i in laserCount:
|
||||
|
||||
@@ -34,7 +34,7 @@ func attack(type):
|
||||
await TickTool.millseconds(randi_range(10, 50))
|
||||
elif type == 1 and health < fields[FieldStore.Entity.MAX_HEALTH] * 0.5 and canSummon:
|
||||
for i in randi_range(1, 2):
|
||||
var child = EntityBase.generate(ComponentManager.getCharacter("KukeChild"), position + MathTool.randv2_range(500))
|
||||
var child = EntityBase.generate(ComponentManager.getCharacter("KukeChild"), position + MathTool.randomVector2In(500))
|
||||
child.currentFocusedBoss = currentFocusedBoss
|
||||
child.masterMine = self
|
||||
elif type == 2:
|
||||
|
||||
@@ -18,5 +18,5 @@ func attack(type: int):
|
||||
func sprint():
|
||||
var target = BulletTool.findClosetBulletCanDamage(position, get_tree(), self)
|
||||
if is_instance_valid(target):
|
||||
var dir = (target.position - position).rotated(MathTool.randc_from([-1, 1]) * deg_to_rad(90))
|
||||
var dir = (target.position - position).rotated(MathTool.randomChoiceFrom([-1, 1]) * deg_to_rad(90))
|
||||
move(dir.normalized() * sprintMultiplier, true)
|
||||
|
||||
@@ -6,5 +6,5 @@ extends FullscreenPanelBase
|
||||
|
||||
func beforeOpen(args: Array = []):
|
||||
audio.play()
|
||||
var reasonTemplate = MathTool.randc_from(GameRule.deadReasons)
|
||||
var reasonTemplate = MathTool.randomChoiceFrom(GameRule.deadReasons)
|
||||
deadreason.text = ("[color=gray]" + reasonTemplate + "凶手是[b]%s[/b]的[b]%s[/b]。[/color]") % args
|
||||
|
||||
@@ -88,7 +88,7 @@ static func spawn(center: Vector2) -> Array:
|
||||
var wave: Wave = data[i]
|
||||
for j in range(entityCountOf(wave)):
|
||||
var currentWave = wave.duplicate()
|
||||
currentWave.entityPosition = MathTool.randv2_range(500) + center
|
||||
currentWave.entityPosition = MathTool.randomRingPoint(200, 1000) + center
|
||||
result.append(currentWave)
|
||||
return result
|
||||
static func next(waves: Array):
|
||||
|
||||
@@ -11,7 +11,7 @@ func attack(entity: EntityBase):
|
||||
var myPos = get_global_mouse_position() + QuickUI.getWindowSize() * Vector2(randf_range(-1, 1) * 0.25, -1)
|
||||
for j in BulletBase.generate(ComponentManager.getBullet("WhiteSoul"), entity,
|
||||
myPos,
|
||||
myPos.angle_to_point(get_global_mouse_position() + MathTool.randv2_range(readStore("radius")))
|
||||
myPos.angle_to_point(get_global_mouse_position() + MathTool.randomVector2In(readStore("radius")))
|
||||
):
|
||||
if j is BulletBase:
|
||||
j.baseDamage = readStore("atk")
|
||||
|
||||
Reference in New Issue
Block a user