# 代码片段

## Code Pieces

pieces of code here.

## A

### Build Game Unit

```lua
local MainQuest = {}
MainQuest.Units = {}

local u_enemy = CreateUnit(uid, GetPlayerPoint(player, 'MainEnemyPoint'), 270, 'Enemy')

function GetPlayerPoint(player, label)
    local pid = player:GetID()
    if label == 'MainEnemyPoint' then
        return {{-512,0}, {512,0}, {0,512}, {0,-512}}[pid]
    end
end

function CreateUnit(uid, point, face, type)
    local unit = ... stuffs here ...
    Matrix.SetupUnitPower(u, type)
    return unit
end

function Matrix.CalcUnitPower(u, type)
    local info = {}
    if type == 'Enemy' then
        info.ATK = G_DIFFICULT * G_CHAPTER * 300
        info.DEF = G_DIFFICULT * G_CHAPTER * 50
        info.HP = G_DIFFICULT * 1000 + G_CHAPTER * 200
    end
    return info
end

function Matrix.AssignUnitPower(u, info)
    if info.ATK then u:SetAttr('ATK', info.ATK) end
    if info.DEF then u:SetAttr('DEF', info.DEF) end
    if info.HP then u:SetAttr('HP', info.HP) end
    if info.MP then u:SetAttr('MP', info.MP) end
    if info.SPD then u:SetAttr('SPD', info.SPD) end
    if info.RNG then u:SetAttr('RNG', info.RNG) end
    if info.SIGHT then u:SetAttr('SIGHT', info.SIGHT) end
end

function Matrix.SetupUnitPower(u, type)
    local info = Matrix.CalcUnitPower(u, type)
    Matrix.AssignUnitPower(info)
end
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://notebook.lazyknight.com/code-pieces.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
