feat: include cached total AP value in each rated dynamic entry
This commit is contained in:
@@ -41,5 +41,7 @@ end
|
||||
module Dynamic = Rated.Dynamic.Make (struct
|
||||
type static = Static.t
|
||||
|
||||
let ic _ = IC.D
|
||||
|
||||
let min_value = 8
|
||||
end)
|
||||
|
||||
@@ -79,6 +79,8 @@ module Melee = struct
|
||||
module Dynamic = Rated.Dynamic.Make (struct
|
||||
type static = Static.t
|
||||
|
||||
let ic (x : static) = x.ic
|
||||
|
||||
let min_value = 6
|
||||
end)
|
||||
end
|
||||
@@ -160,6 +162,8 @@ module Ranged = struct
|
||||
module Dynamic = Rated.Dynamic.Make (struct
|
||||
type static = Static.t
|
||||
|
||||
let ic (x : static) = x.ic
|
||||
|
||||
let min_value = 6
|
||||
end)
|
||||
end
|
||||
|
||||
+15
-15
@@ -3,36 +3,36 @@ type t = A | B | C | D | E
|
||||
let show ic =
|
||||
match ic with A -> "A" | B -> "B" | C -> "C" | D -> "D" | E -> "E"
|
||||
|
||||
let toIndex ic = match ic with A -> 0 | B -> 1 | C -> 2 | D -> 3 | E -> 4
|
||||
let to_index ic = match ic with A -> 0 | B -> 1 | C -> 2 | D -> 3 | E -> 4
|
||||
|
||||
let getApBase ic = match ic with A -> 1 | B -> 2 | C -> 3 | D -> 4 | E -> 15
|
||||
let ap_base ic = match ic with A -> 1 | B -> 2 | C -> 3 | D -> 4 | E -> 15
|
||||
|
||||
(**
|
||||
* Get the value above which the AP values increase linearly. The AP value is
|
||||
* constant until the returned value.
|
||||
*)
|
||||
let getConstantThresholdValue ic = match ic with A | B | C | D -> 12 | E -> 14
|
||||
let constant_threshold_value ic = match ic with A | B | C | D -> 12 | E -> 14
|
||||
|
||||
let getBaseMultiplier ic value =
|
||||
Js.Math.max_int 1 (value - getConstantThresholdValue ic + 1)
|
||||
let base_multiplier ic value =
|
||||
Js.Math.max_int 1 (value - constant_threshold_value ic + 1)
|
||||
|
||||
let getApValue ic value = getApBase ic * getBaseMultiplier ic value
|
||||
let ap_value ic value = ap_base ic * base_multiplier ic value
|
||||
|
||||
let getApForBounds ic (l, u) =
|
||||
let ap_for_bounds ic (l, u) =
|
||||
Ix.range (l + 1, u)
|
||||
|> List.fold_left (fun sum value -> sum + getApValue ic value) 0
|
||||
|> List.fold_left (fun sum value -> sum + ap_value ic value) 0
|
||||
|
||||
let getApForRange ic ~fromValue ~toValue =
|
||||
if fromValue == toValue then 0
|
||||
let ap_for_range ic ~from_value ~to_value =
|
||||
if from_value == to_value then 0
|
||||
else
|
||||
getApForBounds ic (Int.minmax fromValue toValue)
|
||||
* if fromValue > toValue then -1 else 1
|
||||
ap_for_bounds ic (Int.minmax from_value to_value)
|
||||
* if from_value > to_value then -1 else 1
|
||||
|
||||
let getApForIncrease ic fromValue = getApValue ic (fromValue + 1)
|
||||
let ap_for_increase ic from_value = ap_value ic (from_value + 1)
|
||||
|
||||
let getApForDecrease ic fromValue = -getApValue ic fromValue
|
||||
let ap_for_decrease ic from_value = -ap_value ic from_value
|
||||
|
||||
let getApForActivatation = getApBase
|
||||
let ap_for_activatation = ap_base
|
||||
|
||||
module Decode = struct
|
||||
open Json.Decode
|
||||
|
||||
+13
-27
@@ -4,38 +4,24 @@
|
||||
type t = A | B | C | D | E
|
||||
|
||||
val show : t -> string
|
||||
(**
|
||||
* Returns the name of the passed Improvement Cost.
|
||||
*)
|
||||
(** Returns the name of the passed Improvement Cost. *)
|
||||
|
||||
val toIndex : t -> int
|
||||
(**
|
||||
* Returns an index used for getting the IC-based cost for an Activatable entry.
|
||||
*)
|
||||
val to_index : t -> int
|
||||
(** Returns an index used for getting the IC-based cost for an Activatable
|
||||
entry. *)
|
||||
|
||||
val getApForRange : t -> fromValue:int -> toValue:int -> int
|
||||
(**
|
||||
* `getApForRange ic fromSr toSr` returns the AP cost for the given Skill Point
|
||||
* range with the given `ic`.
|
||||
*)
|
||||
val ap_for_range : t -> from_value:int -> to_value:int -> int
|
||||
(** [ap_for_range ic ~from_value ~to_value] returns the AP cost for the given
|
||||
Skill Point range with the given [ic]. *)
|
||||
|
||||
val getApForIncrease : t -> int -> int
|
||||
(**
|
||||
* `getApForIncrease ic sr` returns the AP cost for adding one Skill Point to
|
||||
* `fromSr` with the given `ic`.
|
||||
*)
|
||||
val ap_for_increase : t -> int -> int
|
||||
(** [ap_for_increase ic sr] returns the AP cost for adding one Skill Point to [sr] with the given [ic]. *)
|
||||
|
||||
val getApForDecrease : t -> int -> int
|
||||
(**
|
||||
* `getAPForDec ic sr` returns the AP cost for removing one Skill Point from
|
||||
* `fromSr` with the given `ic`.
|
||||
*)
|
||||
val ap_for_decrease : t -> int -> int
|
||||
(** [ap_for_decrease ic sr] returns the AP cost for removing one Skill Point from [sr] with the given [ic]. *)
|
||||
|
||||
val getApForActivatation : t -> int
|
||||
(**
|
||||
* `getAPForActivatation ic` returns the AP cost for activating an entry with
|
||||
* the given `ic`.
|
||||
*)
|
||||
val ap_for_activatation : t -> int
|
||||
(** `ap_for_activatation ic` returns the AP cost for activating an entry with the given [ic]. *)
|
||||
|
||||
module Decode : sig
|
||||
val t : Js.Json.t -> t
|
||||
|
||||
+26
-2
@@ -10,6 +10,7 @@ module Dynamic = struct
|
||||
type 'static t = {
|
||||
id : int;
|
||||
value : int;
|
||||
cached_ap : int;
|
||||
dependencies : dependency list;
|
||||
static : 'static option;
|
||||
}
|
||||
@@ -19,7 +20,9 @@ module Dynamic = struct
|
||||
|
||||
type nonrec t = static t
|
||||
|
||||
val empty : static option -> int -> t
|
||||
val make : ?value:int -> static:static option -> id:int -> t
|
||||
|
||||
val update_value : (int -> int) -> t -> t
|
||||
|
||||
val is_empty : t -> bool
|
||||
|
||||
@@ -30,6 +33,9 @@ module Dynamic = struct
|
||||
type static
|
||||
(** The static values from the database. *)
|
||||
|
||||
val ic : static -> IC.t
|
||||
(** Get the improvement cost from the static entry. *)
|
||||
|
||||
val min_value : int
|
||||
(** The minimum possible value of the entry. *)
|
||||
end
|
||||
@@ -41,7 +47,25 @@ module Dynamic = struct
|
||||
|
||||
let min_value = Config.min_value
|
||||
|
||||
let empty static id = { id; value = min_value; dependencies = []; static }
|
||||
let ap_total static value =
|
||||
let open Option.Infix in
|
||||
static <&> Config.ic
|
||||
<&> IC.ap_for_range ~from_value:min_value ~to_value:value
|
||||
|> Option.fromOption 0
|
||||
|
||||
let make ?(value = min_value) ~static ~id =
|
||||
let init_value = Int.max min_value value in
|
||||
{
|
||||
id;
|
||||
value = init_value;
|
||||
cached_ap = ap_total static init_value;
|
||||
dependencies = [];
|
||||
static;
|
||||
}
|
||||
|
||||
let update_value f (x : t) =
|
||||
let new_value = Int.max min_value (f x.value) in
|
||||
{ x with value = new_value; cached_ap = ap_total x.static new_value }
|
||||
|
||||
let is_empty (x : t) = x.value <= min_value && ListX.null x.dependencies
|
||||
|
||||
|
||||
+13
-2
@@ -18,6 +18,7 @@ module Dynamic : sig
|
||||
type 'static t = {
|
||||
id : int; (** The rated entry'd identifier. *)
|
||||
value : int; (** The current value. *)
|
||||
cached_ap : int; (** The accumulated AP value of all value increases. *)
|
||||
dependencies : dependency list; (** The list of dependencies. *)
|
||||
static : 'static option;
|
||||
(** The corresponding static data entry for easy access. *)
|
||||
@@ -32,8 +33,15 @@ module Dynamic : sig
|
||||
(** The dynamic values in a character with a reference to the static values
|
||||
from the database. *)
|
||||
|
||||
val empty : static option -> int -> t
|
||||
(** [empty id] creates a new dynamic entry from an id. *)
|
||||
val make : ?value:int -> static:static option -> id:int -> t
|
||||
(** [make ~value ~static ~id] creates a new dynamic entry from an id. If a
|
||||
value is provided and a static entry is present, it inserts the value
|
||||
and calculates the initial total AP cache. *)
|
||||
|
||||
val update_value : (int -> int) -> t -> t
|
||||
(** [update_value f x] updates the value of the entry [x] using the function
|
||||
[f] that receives the old value as has to return the new one. It also
|
||||
updates its total AP value if a static entry is present. *)
|
||||
|
||||
val is_empty : t -> bool
|
||||
(** [is_empty x] checks if the passed dynamic entry is empty. *)
|
||||
@@ -49,6 +57,9 @@ module Dynamic : sig
|
||||
type static
|
||||
(** The static values from the database. *)
|
||||
|
||||
val ic : static -> IC.t
|
||||
(** Get the improvement cost from the static entry. *)
|
||||
|
||||
val min_value : int
|
||||
(** The minimum possible value of the entry. *)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user