191 lines
5.0 KiB
Markdown
191 lines
5.0 KiB
Markdown
# Skill Conversion Example
|
|
|
|
## What Gets Converted
|
|
|
|
### Input: C++ skill1.h
|
|
```cpp
|
|
class Skill1Stub : public SkillStub
|
|
{
|
|
public:
|
|
Skill1Stub() : SkillStub(1)
|
|
{
|
|
name = L"虎击";
|
|
icon = L"虎击.dds";
|
|
max_level = 10;
|
|
allow_land = 1;
|
|
allow_air = 1;
|
|
range.type = 0;
|
|
}
|
|
|
|
float GetMpcost(Skill * skill) const
|
|
{
|
|
return (float)(-5 + 7 * skill->GetLevel());
|
|
}
|
|
|
|
int GetExecutetime(Skill * skill) const
|
|
{
|
|
return 700;
|
|
}
|
|
|
|
class State1 : public SkillStub::State
|
|
{
|
|
public:
|
|
virtual int GetTime(Skill * skill) const
|
|
{
|
|
return 400;
|
|
}
|
|
virtual void Calculate(Skill * skill) const
|
|
{
|
|
skill->GetPlayer()->SetDecmp(0.2 *(-5 + 7 * skill->GetLevel()));
|
|
}
|
|
};
|
|
};
|
|
```
|
|
|
|
### Output: C# skill1.cs
|
|
```csharp
|
|
public class Skill1Stub : SkillStub
|
|
{
|
|
public Skill1Stub() : base(1)
|
|
{
|
|
name = "虎击";
|
|
icon = "虎击"; // Extension removed!
|
|
max_level = 10;
|
|
allow_land = true; // Converted to bool!
|
|
allow_air = true;
|
|
range = new Range();
|
|
range.type = 0;
|
|
}
|
|
|
|
public override float GetMpcost(Skill skill) => (float)(-5 + 7 * skill.GetLevel());
|
|
|
|
public override int GetExecutetime(Skill skill) => 700;
|
|
|
|
#if SKILL_SERVER
|
|
public class State1 : SkillStub.State
|
|
{
|
|
public int GetTime(Skill skill) => 400;
|
|
public void Calculate(Skill skill)
|
|
{
|
|
skill.GetPlayer().SetDecmp(0.2f *(-5 + 7 * skill.GetLevel()));
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
```
|
|
|
|
## Key Changes Made
|
|
|
|
### 1. ✅ GetIntroduction Method (YOUR FIX!)
|
|
**Before (old script):**
|
|
```csharp
|
|
public int GetIntroduction(Skill skill, StringBuilder buffer, int length, string format)
|
|
{
|
|
string result = string.Format(format, params...);
|
|
if (result.Length < length)
|
|
{
|
|
buffer.Append(result);
|
|
return result.Length;
|
|
}
|
|
return 0;
|
|
}
|
|
```
|
|
|
|
**After (fixed script):**
|
|
```csharp
|
|
public override int GetIntroduction(Skill skill, StringBuilder buffer, string format)
|
|
{
|
|
buffer.Append(GPDataTypeHelper.ReplacePercentD(format,
|
|
skill.GetLevel(),
|
|
-5 + 7 * skill.GetLevel(),
|
|
1.9 * skill.GetLevel() * skill.GetLevel() + 64 * skill.GetLevel() + 36.7));
|
|
return buffer.Length;
|
|
}
|
|
```
|
|
|
|
### 2. ✅ Syntax Conversions
|
|
- `->` becomes `.` (pointer to member access)
|
|
- `L"text"` becomes `"text"` (wide string literals)
|
|
- `1`/`0` becomes `true`/`false` for boolean fields
|
|
- `.dds`, `.sgc` extensions removed from icon/effect paths
|
|
- Added `override` keyword where needed
|
|
- Added `f` suffix to float literals
|
|
|
|
### 3. ✅ Structure Organization
|
|
- `#if SKILL_SERVER` wraps server-only code
|
|
- `#if SKILL_CLIENT` wraps client-only code
|
|
- States properly nested
|
|
- Constructor calls `base(id)` instead of `: SkillStub(id)`
|
|
|
|
## File Organization After Conversion
|
|
|
|
```
|
|
E:\Projects\perfect-world-unity\Assets\PerfectWorld\Scripts\Skills\
|
|
├── SkillStubs1\
|
|
│ ├── skill1.cs
|
|
│ ├── skill2.cs
|
|
│ ├── skill3.cs
|
|
│ ├── ...
|
|
│ ├── skill100.cs
|
|
│ └── SkillStubs1.cs ← Auto-generated registration file
|
|
├── SkillStubs2\
|
|
│ ├── skill101.cs
|
|
│ ├── ...
|
|
│ └── SkillStubs2.cs
|
|
└── ...
|
|
```
|
|
|
|
## SkillStubs1.cs Registration File
|
|
```csharp
|
|
using BrewMonster.Scripts.Skills;
|
|
using UnityEngine;
|
|
|
|
namespace BrewMonster
|
|
{
|
|
public static partial class SkillStubs
|
|
{
|
|
// Skill stub declarations
|
|
public static Skill1Stub __stub_Skill1Stub = new Skill1Stub();
|
|
public static Skill2Stub __stub_Skill2Stub = new Skill2Stub();
|
|
public static Skill3Stub __stub_Skill3Stub = new Skill3Stub();
|
|
// ... all skills ...
|
|
|
|
#if SKILL_SERVER
|
|
public static Skill1 __stub_Skill1 = new Skill1();
|
|
public static Skill2 __stub_Skill2 = new Skill2();
|
|
public static Skill3 __stub_Skill3 = new Skill3();
|
|
// ... all skills ...
|
|
#endif
|
|
}
|
|
}
|
|
```
|
|
|
|
## Verification Checklist
|
|
|
|
After conversion, verify:
|
|
- ✅ No compilation errors in Unity
|
|
- ✅ Chinese characters display correctly
|
|
- ✅ Icon names match your Unity assets (no .dds extension)
|
|
- ✅ Skill descriptions show properly with `GPDataTypeHelper.ReplacePercentD`
|
|
- ✅ All methods have correct `override` keyword
|
|
- ✅ Float values have `f` suffix
|
|
- ✅ Boolean fields use `true`/`false` not `1`/`0`
|
|
|
|
## Common Issues & Fixes
|
|
|
|
### Issue: "Cannot convert int to bool"
|
|
**Cause:** Old conversion script didn't convert boolean fields
|
|
**Fix:** ✅ Already fixed! Script now converts `1`→`true`, `0`→`false`
|
|
|
|
### Issue: "Method does not override"
|
|
**Cause:** Missing `override` keyword
|
|
**Fix:** ✅ Already fixed! Script adds `override` for GetMpcost, GetIntroduction, etc.
|
|
|
|
### Issue: Skill description shows "{0} {1}" instead of values
|
|
**Cause:** Not using `GPDataTypeHelper.ReplacePercentD`
|
|
**Fix:** ✅ Already fixed! Your change uses `ReplacePercentD` now
|
|
|
|
### Issue: Icon not found in Unity
|
|
**Cause:** File extension in icon path
|
|
**Fix:** ✅ Already fixed! Script removes `.dds`, `.sgc` extensions
|