这次给你们分享个JASS判断主属性的分享 JASS语法已经每行批注直接触发器新建转换为JASS然后删除复制粘贴就可以用
by:两仪·煜
以下是代码:
library SmartAttributeDetector initializer init
// 智能主属性判断系统
// 功能:自动识别单位的主属性类型并增加对应的属性值
//SmartAttributeDetector_GetPrimaryAttributeValue(GetTriggerUnit())为判断主属性的值
//SmartAttributeDetector_GetAttributeName(GetTriggerUnit())为判断主属性的名字
//call SmartAttributeDetector_AddPrimaryAttributeValue(GetTriggerUnit(), 5.0)为增加5点主属性
globals
// 定义主属性类型的常量
private constant integer ATTR_STR = 1 // 力量类型标识
private constant integer ATTR_AGI = 2 // 敏捷类型标识
private constant integer ATTR_INT = 3 // 智力类型标识
private constant integer ATTR_NONE = 0 // 无主属性标识(非英雄单位)
endglobals
// 获取单位的主属性类型
public function GetUnitPrimaryAttribute takes unit u returns integer
// 首先检查是否为英雄单位
if not IsUnitType(u, UNIT_TYPE_HERO) then
return ATTR_NONE // 非英雄单位返回无主属性标识
endif
// 获取单位的类型ID用于判断主属性
local integer unitId = GetUnitTypeId(u)
// 通过单位ID判断主属性类型
if unitId == 0x4870616C or unitId == 0x486D6B67 then
return ATTR_STR // 这些ID对应的单位是力量型英雄
elseif unitId == 0x48626C6D or unitId == 0x48616D67 then
return ATTR_INT // 这些ID对应的单位是智力型英雄
elseif unitId == 0x48767368 or unitId == 0x48616E74 then
return ATTR_AGI // 这些ID对应的单位是敏捷型英雄
endif
// 默认情况下返回力量型(安全回退)
return ATTR_STR
endfunction
// 判断单位是否为力量型英雄
public function IsStrengthHero takes unit u returns boolean
return GetUnitPrimaryAttribute(u) == ATTR_STR
endfunction
// 判断单位是否为敏捷型英雄
public function IsAgilityHero takes unit u returns boolean
return GetUnitPrimaryAttribute(u) == ATTR_AGI
endfunction
// 判断单位是否为智力型英雄
public function IsIntelligenceHero takes unit u returns boolean
return GetUnitPrimaryAttribute(u) == ATTR_INT
endfunction
// 获取主属性名称(中文显示)
public function GetAttributeName takes unit u returns string
local integer attr = GetUnitPrimaryAttribute(u)
// 根据主属性类型返回对应的中文名称
if attr == ATTR_STR then
return "力量"
elseif attr == ATTR_AGI then
return "敏捷"
elseif attr == ATTR_INT then
return "智力"
endif
// 非英雄单位或无主属性情况
return "无主属性"
endfunction
// 智能获取主属性值(核心功能)
public function GetPrimaryAttributeValue takes unit u returns real
local integer attrType = GetUnitPrimaryAttribute(u)
local integer attrValue = 0 // 临时存储整数值
// 根据主属性类型获取对应的属性值
if attrType == ATTR_STR then
set attrValue = GetHeroStr(u, true) // 获取力量值(包含加成)
elseif attrType == ATTR_AGI then
set attrValue = GetHeroAgi(u, true) // 获取敏捷值(包含加成)
elseif attrType == ATTR_INT then
set attrValue = GetHeroInt(u, true) // 获取智力值(包含加成)
endif
// 将整数值转换为实数类型返回
return I2R(attrValue)
endfunction
// 新增:增加主属性值(核心功能)
public function AddPrimaryAttributeValue takes unit u, real amount returns nothing
local integer attrType = GetUnitPrimaryAttribute(u)
local integer intAmount = R2I(amount) // 将实数转换为整数
// 根据主属性类型增加对应的属性值
if attrType == ATTR_STR then
call SetHeroStr(u, GetHeroStr(u, false) + intAmount, true)
elseif attrType == ATTR_AGI then
call SetHeroAgi(u, GetHeroAgi(u, false) + intAmount, true)
elseif attrType == ATTR_INT then
call SetHeroInt(u, GetHeroInt(u, false) + intAmount, true)
endif
endfunction
// 初始化函数 - 添加系统启动提示
private function init takes nothing returns nothing
// 在屏幕上显示绿色文字提示
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "|cff00ff00智能主属性系统加载完成|r")
endfunction
endlibrary
by:两仪·煜
以下是代码:
library SmartAttributeDetector initializer init
// 智能主属性判断系统
// 功能:自动识别单位的主属性类型并增加对应的属性值
//SmartAttributeDetector_GetPrimaryAttributeValue(GetTriggerUnit())为判断主属性的值
//SmartAttributeDetector_GetAttributeName(GetTriggerUnit())为判断主属性的名字
//call SmartAttributeDetector_AddPrimaryAttributeValue(GetTriggerUnit(), 5.0)为增加5点主属性
globals
// 定义主属性类型的常量
private constant integer ATTR_STR = 1 // 力量类型标识
private constant integer ATTR_AGI = 2 // 敏捷类型标识
private constant integer ATTR_INT = 3 // 智力类型标识
private constant integer ATTR_NONE = 0 // 无主属性标识(非英雄单位)
endglobals
// 获取单位的主属性类型
public function GetUnitPrimaryAttribute takes unit u returns integer
// 首先检查是否为英雄单位
if not IsUnitType(u, UNIT_TYPE_HERO) then
return ATTR_NONE // 非英雄单位返回无主属性标识
endif
// 获取单位的类型ID用于判断主属性
local integer unitId = GetUnitTypeId(u)
// 通过单位ID判断主属性类型
if unitId == 0x4870616C or unitId == 0x486D6B67 then
return ATTR_STR // 这些ID对应的单位是力量型英雄
elseif unitId == 0x48626C6D or unitId == 0x48616D67 then
return ATTR_INT // 这些ID对应的单位是智力型英雄
elseif unitId == 0x48767368 or unitId == 0x48616E74 then
return ATTR_AGI // 这些ID对应的单位是敏捷型英雄
endif
// 默认情况下返回力量型(安全回退)
return ATTR_STR
endfunction
// 判断单位是否为力量型英雄
public function IsStrengthHero takes unit u returns boolean
return GetUnitPrimaryAttribute(u) == ATTR_STR
endfunction
// 判断单位是否为敏捷型英雄
public function IsAgilityHero takes unit u returns boolean
return GetUnitPrimaryAttribute(u) == ATTR_AGI
endfunction
// 判断单位是否为智力型英雄
public function IsIntelligenceHero takes unit u returns boolean
return GetUnitPrimaryAttribute(u) == ATTR_INT
endfunction
// 获取主属性名称(中文显示)
public function GetAttributeName takes unit u returns string
local integer attr = GetUnitPrimaryAttribute(u)
// 根据主属性类型返回对应的中文名称
if attr == ATTR_STR then
return "力量"
elseif attr == ATTR_AGI then
return "敏捷"
elseif attr == ATTR_INT then
return "智力"
endif
// 非英雄单位或无主属性情况
return "无主属性"
endfunction
// 智能获取主属性值(核心功能)
public function GetPrimaryAttributeValue takes unit u returns real
local integer attrType = GetUnitPrimaryAttribute(u)
local integer attrValue = 0 // 临时存储整数值
// 根据主属性类型获取对应的属性值
if attrType == ATTR_STR then
set attrValue = GetHeroStr(u, true) // 获取力量值(包含加成)
elseif attrType == ATTR_AGI then
set attrValue = GetHeroAgi(u, true) // 获取敏捷值(包含加成)
elseif attrType == ATTR_INT then
set attrValue = GetHeroInt(u, true) // 获取智力值(包含加成)
endif
// 将整数值转换为实数类型返回
return I2R(attrValue)
endfunction
// 新增:增加主属性值(核心功能)
public function AddPrimaryAttributeValue takes unit u, real amount returns nothing
local integer attrType = GetUnitPrimaryAttribute(u)
local integer intAmount = R2I(amount) // 将实数转换为整数
// 根据主属性类型增加对应的属性值
if attrType == ATTR_STR then
call SetHeroStr(u, GetHeroStr(u, false) + intAmount, true)
elseif attrType == ATTR_AGI then
call SetHeroAgi(u, GetHeroAgi(u, false) + intAmount, true)
elseif attrType == ATTR_INT then
call SetHeroInt(u, GetHeroInt(u, false) + intAmount, true)
endif
endfunction
// 初始化函数 - 添加系统启动提示
private function init takes nothing returns nothing
// 在屏幕上显示绿色文字提示
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "|cff00ff00智能主属性系统加载完成|r")
endfunction
endlibrary











