zig update

This commit is contained in:
shenjack 2024-05-03 23:31:43 +08:00
parent 64d17813c2
commit 6df02fe5e2
Signed by: shenjack
GPG Key ID: 7B1134A979775551
4 changed files with 82 additions and 50 deletions

View File

@ -136,9 +136,8 @@ impl Namer {
let name_len = name_bytes.len();
let b_name_len = name_len + 1;
for _ in 0..2 {
let mut s = 0_u8;
unsafe {
val.swap_unchecked(s as usize, 0);
let mut s = 0_u8;
let mut k = 0;
for i in 0..256 {
s = s.wrapping_add(if k == 0 { 0 } else { *name_bytes.get_unchecked(k - 1) });
@ -503,17 +502,22 @@ impl Namer {
min(*self.name_base.get_unchecked(i + 2), *self.name_base.get_unchecked(i + 3)),
)
};
if p > 10 && skill_id[j] < 35 {
self.skl_freq[j] = p - 10;
if skill_id[j] < 25 {
last = j as i32;
};
} else {
self.skl_freq[j] = 0
unsafe {
if p > 10 && *skill_id.get_unchecked(j) < 35 {
*self.skl_freq.get_unchecked_mut(j) = p - 10;
if *skill_id.get_unchecked(j) < 25 {
last = j as i32;
}
} else {
*self.skl_freq.get_unchecked_mut(j) = 0;
}
}
}
if last != -1 {
self.skl_freq[last as usize] <<= 1;
// self.skl_freq[last as usize] <<= 1;
unsafe {
*self.skl_freq.get_unchecked_mut(last as usize) <<= 1;
}
// *= 2
}
if (self.skl_freq[14] != 0) && (last != 14) {
@ -533,48 +537,10 @@ impl Namer {
#[inline(always)]
pub fn get_property(&self) -> f32 {
unsafe {
// (self.name_prop.get_unchecked(1)
// + self.name_prop.get_unchecked(2)
// + self.name_prop.get_unchecked(3)
// + self.name_prop.get_unchecked(4)
// + self.name_prop.get_unchecked(5)
// + self.name_prop.get_unchecked(6)
// + self.name_prop.get_unchecked(7)) as f32
// + (*self.name_prop.get_unchecked(0) as f32 / 3_f32)
self.name_prop.get_unchecked(1..=7).iter().sum::<u32>() as f32 + (*self.name_prop.get_unchecked(0) as f32 / 3_f32)
}
}
pub fn get_净化(&self) -> u8 {
// self.skl_freq[17]
for (i, v) in self.skl_freq.iter().enumerate() {
if *v != 0 && self.skl_id[i] == 17 {
return *v;
}
}
0
}
pub fn get_分身(&self) -> u8 {
// self.skl_freq[23]
for (i, v) in self.skl_freq.iter().enumerate() {
if *v != 0 && self.skl_id[i] == 23 {
return *v;
}
}
0
}
pub fn get_幻术(&self) -> u8 {
// self.skl_freq[24]
for (i, v) in self.skl_freq.iter().enumerate() {
if *v != 0 && self.skl_id[i] == 24 {
return *v;
}
}
0
}
pub fn get_info(&self) -> String {
let main = format!(
"name: {}, team: {} HP|{} 攻|{} 防|{} 速|{} 敏|{} 魔|{} 抗|{} 智|{} 八围:{}",

3
zigs/.gitignore vendored
View File

@ -1 +1,2 @@
zig-cache
zig-cache
zig-out

View File

@ -2,7 +2,7 @@
.name = "zigs",
// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",
.version = "0.0.1",
// This field is optional.
// This is currently advisory only; Zig does not yet do anything

View File

@ -22,3 +22,68 @@ test "simple test" {
try list.append(42);
try std.testing.expectEqual(@as(i32, 42), list.pop());
}
const val_init = [256]u8{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
};
const Teamer = struct {
val: [256]u8,
// :
pub fn new(team_name: []const u8) Teamer {
var val = val_init;
const t_len = team_name.len + 1;
var s = 0;
for (0..256) |i| {
if (i % t_len != 0) {
s +%= team_name[i % t_len - 1];
}
s +%= val[i];
// swap i and s
const tmp = val[i];
val[i] = val[s];
val[s] = tmp;
}
return Teamer{ .val = val };
}
};
const Namer = struct {
// code from rust
// pub val: [u8; 256],
// pub name_base: [u8; 128],
// pub name_prop: [u32; 8],
// pub skl_id: [u8; 40],
// pub skl_freq: [u8; 40],
val: [256]u8,
name_base: [128]u8,
name_prop: [8]u32,
skl_id: [40]u8,
skl_freq: [40]u8,
pub fn new(team: Teamer, name: []const u8) Namer {
var val = team.val;
var name_base = [0]u8;
var name_prop = [0]u32;
var skl_id = [0]u8;
var skl_freq = [0]u8;
const name_len = name.len + 1;
}
};