aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


server/nano_healing.go (3815B)


      1 package main
      2 
      3 import (
      4 	"ao/server/gamedata"
      5 	"slices"
      6 )
      7 
      8 func directHealingNano(program uint32) *gamedata.ItemFunction {
      9 	return healingHitNano(program, false)
     10 }
     11 
     12 func healingOverTimeNano(program uint32) *gamedata.ItemFunction {
     13 	return healingHitNano(program, true)
     14 }
     15 
     16 func healingHitNano(program uint32, periodic bool) *gamedata.ItemFunction {
     17 	definition := gamedata.NanoTemplates[program]
     18 	if definition == nil || definition.RecordType != 1040005 || definition.HeaderWords[0] != 51051 || definition.Undecoded != nil ||
     19 		itemStat(definition, 30) != 0 || itemStat(definition, 76) != 0 || itemStat(definition, 405) != 2 || len(definition.Sections) != 4 {
     20 		return nil
     21 	}
     22 	if periodic {
     23 		if flags := itemStat(definition, 0); flags != 0x10002 && flags != 0x80010002 {
     24 			return nil
     25 		}
     26 		for _, stat := range []uint32{8, 54, 75} {
     27 			if value := itemStat(definition, stat); value == 0 || value >= 0x80000000 {
     28 				return nil
     29 			}
     30 		}
     31 	} else if (itemStat(definition, 0) != 0x80000002 && itemStat(definition, 0) != 2) || itemStat(definition, 8) != 0 {
     32 		return nil
     33 	}
     34 	for _, stat := range []uint32{210, 287, 294, 407} {
     35 		if value := nanoStat(program, stat); value == 0 || value >= 0x80000000 {
     36 			return nil
     37 		}
     38 	}
     39 
     40 	// Ordinary heals have an attack rating and at most an authored zero defense.
     41 	weights, defaults := definition.Sections[0], definition.Sections[1]
     42 	if weights.Type != 4 || weights.Subtype != 4 || weights.Entries == nil || len(*weights.Entries) < 1 || len(*weights.Entries) > 2 ||
     43 		defaults.Type != 6 || defaults.Subtype != 27 || defaults.Stats == nil {
     44 		return nil
     45 	}
     46 	attack := (*weights.Entries)[0]
     47 	if len(*weights.Entries) == 2 {
     48 		defense := (*weights.Entries)[1]
     49 		if attack.Type != nil && *attack.Type == 13 {
     50 			attack, defense = defense, attack
     51 		}
     52 		if !periodic || defense.Type == nil || *defense.Type != 13 || defense.Stats == nil || !slices.Equal(*defense.Stats, [][2]uint32{{168, 0}}) {
     53 			return nil
     54 		}
     55 	}
     56 	if !slices.Equal(*defaults.Stats, [][2]uint32{{12, 0}}) &&
     57 		(!periodic || !slices.Equal(*defaults.Stats, [][2]uint32{{12, 0}, {13, 0}})) {
     58 		return nil
     59 	}
     60 	if attack.Type == nil || *attack.Type != 12 || attack.Stats == nil {
     61 		return nil
     62 	}
     63 	var total uint32
     64 	for _, weight := range *attack.Stats {
     65 		if weight[0] < 100 || weight[0] > 168 || weight[1] == 0 || weight[1] > 100 {
     66 			return nil
     67 		}
     68 		total += weight[1]
     69 	}
     70 	if total != 100 {
     71 		return nil
     72 	}
     73 
     74 	// Admit the complete selected-target HP contract, not a partial effect.
     75 	effects, requirements := definition.Sections[2], definition.Sections[3]
     76 	if effects.Type != 2 || effects.Subtype != 0 || effects.Functions == nil || len(*effects.Functions) != 1 ||
     77 		requirements.Type != 22 || requirements.Subtype != 36 || requirements.Actions == nil || len(*requirements.Actions) != 1 || (*requirements.Actions)[0].Type != 3 {
     78 		return nil
     79 	}
     80 	for _, requirement := range (*requirements.Actions)[0].Requirements {
     81 		switch requirement.Operator {
     82 		case 3, 4, 42:
     83 		default:
     84 			if _, known := (&character{}).meetsStatRequirement(requirement); !known {
     85 				return nil
     86 			}
     87 		}
     88 	}
     89 	hit := &(*effects.Functions)[0]
     90 	if hit.ID != 53002 || hit.HeaderWords != [2]uint32{0, 4} || hit.ArgumentHeader != 9 || hit.Target != 3 ||
     91 		len(hit.Requirements) != 0 || len(hit.Arguments) != 4 {
     92 		return nil
     93 	}
     94 	if periodic {
     95 		if hit.TickCount < 2 || hit.TickInterval == 0 || uint64(hit.TickCount)*uint64(hit.TickInterval) != uint64(itemStat(definition, 8)) {
     96 			return nil
     97 		}
     98 	} else if hit.TickCount != 1 || hit.TickInterval != 0 {
     99 		return nil
    100 	}
    101 	for _, argument := range hit.Arguments {
    102 		if argument.Integer == nil {
    103 			return nil
    104 		}
    105 	}
    106 	if *hit.Arguments[0].Integer != 27 || *hit.Arguments[1].Integer <= 0 || *hit.Arguments[2].Integer < *hit.Arguments[1].Integer || *hit.Arguments[3].Integer != 0 {
    107 		return nil
    108 	}
    109 	return hit
    110 }