Skip to content

Commit

Permalink
homunculus
Browse files Browse the repository at this point in the history
  • Loading branch information
issid committed Apr 14, 2022
1 parent 303cd12 commit e332233
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 139 deletions.
12 changes: 6 additions & 6 deletions AI/AI.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

require "AI\\Const"
require "AI\\Util"
require "AI/Const.lua"
require "AI/Util.lua"

-----------------------------
-- state
Expand Down Expand Up @@ -53,13 +53,13 @@ function OnMOVE_CMD (x,y)
TraceAI ("OnMOVE_CMD")

if ( x == MyDestX and y == MyDestY and MOTION_MOVE == GetV(V_MOTION,MyID)) then
return -- 현재 이동중인 목적지와 같은 곳이면 처리하지 않는다.
return -- If it is the same as the current destination, it will not be processed.
end

local curX, curY = GetV (V_POSITION,MyID)
if (math.abs(x-curX)+math.abs(y-curY) > 15) then -- 목적지가 일정 거리 이상이면 (서버에서 먼거리는 처리하지 않기 때문에)
List.pushleft (ResCmdList,{MOVE_CMD,x,y}) -- 원래 목적지로의 이동을 예약한다.
x = math.floor((x+curX)/2) -- 중간지점으로 먼저 이동한다.
if (math.abs(x-curX)+math.abs(y-curY) > 15) then -- If the destination is more than a certain distance (since the server does not handle the long distance)
List.pushleft (ResCmdList,{MOVE_CMD,x,y}) -- Book a transfer to your original destination.
x = math.floor((x+curX)/2) -- Go to the midpoint first.
y = math.floor((y+curY)/2) --
end

Expand Down
2 changes: 1 addition & 1 deletion AI/Util.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

require "AI\\Const"
require "AI/Const.lua"

--------------------------------------------
-- List utility
Expand Down
17 changes: 8 additions & 9 deletions src/Controls/EntityControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ define(function( require )
var ChatRoom = require('UI/Components/ChatRoom/ChatRoom');
var ContextMenu = require('UI/Components/ContextMenu/ContextMenu');
var Pet = require('UI/Components/PetInformations/PetInformations');
// todo error use shortcat skill SkillTargetSelection.js
// var Homun = require('UI/Components/HomunInformations/HomunInformations');
var Trade = require('UI/Components/Trade/Trade');
var getModule = require;

Expand Down Expand Up @@ -287,13 +285,14 @@ define(function( require )
break;

case Entity.TYPE_HOM:
// if (Session.homunId === this.GID) {
// ContextMenu.remove();
// ContextMenu.append();
// ContextMenu.addElement( 'View Status', Homun.ui.show.bind(Homun.ui));
// ContextMenu.addElement( 'Feed', Homun.reqHomunFeed());
// ContextMenu.addElement( 'Stand By', Homun.reqMoveToOwner(this.GID));
// }
if (Session.homunId === this.GID) {
ContextMenu.remove();
ContextMenu.append();
// todo homunculus implement
ContextMenu.addElement( 'View Status', () => console.warn('"View Status" not implemented'));
ContextMenu.addElement( 'Feed', () => console.warn('"Feed" not implemented'));
ContextMenu.addElement( 'Stand By', () => console.warn('"Stand By" not implemented'));
}
break;
}

Expand Down
11 changes: 3 additions & 8 deletions src/Controls/MapControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ define(function( require )
var Session = require('Engine/SessionStorage');
var Preferences = require('Preferences/Controls');
var KEYS = require('Controls/KeyEventHandler');
var HomunInformations = require('UI/Components/HomunInformations/HomunInformations');
var AIDriver = require('Utils/AIDriver');
var AIDriver = require('Core/AIDriver');

require('Controls/ScreenShot');

Expand Down Expand Up @@ -139,14 +138,10 @@ define(function( require )
Cursor.setType( Cursor.ACTION.ROTATE );
Camera.rotate( false );

HomunInformations.reqMoveTo(Session.homunId);
// AIDriver.exec('Move(' + Session.homunId + ', ' + entityOver.position.x + ', ' + entityOver.position.y + ')');
AIDriver.setmsg(Session.homunId, '1,'+ Mouse.world.x + ',' + Mouse.world.y);

if (entityOver) {
//todo focus attack
// AIDriver.setmsg(3, entityOver.GID)
// AIDriver.exec('Attack('+Session.homunId+', '+entityOver.GID+')');
HomunInformations.reqAttack(Session.homunId, entityOver.GID);
AIDriver.setmsg(Session.homunId, '3,'+ entityOver.GID);
}
} else {
Cursor.setType( Cursor.ACTION.ROTATE );
Expand Down
88 changes: 43 additions & 45 deletions src/Utils/AIDriver.js → src/Core/AIDriver.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
define(['Vendors/lua.vm', 'Renderer/EntityManager', 'Renderer/Renderer'], function (LUA_VM, EntityManager, Renderer) {
define(['Renderer/EntityManager', 'Renderer/Renderer', 'Vendors/fengari-web', 'Renderer/Entity/Entity'], function (EntityManager, Renderer, fengari, Entity) {
'use strict';

var Session = require('Engine/SessionStorage');
var Network = require('Network/NetworkManager');
var PACKET = require('Network/PacketStructure');

// var HomunInformations = require('UI/Components/HomunInformations/HomunInformations');
// var Homun = require('Engine/MapEngine/Homun');
// var Entity = require('Renderer/Entity/Entity');

function AIDriver() {
}

AIDriver.init = function init() {
AIDriver.exec(`
require "AI\\\\AI"
require "AI/AI.lua"
function TraceAI (string)
function TraceAI (string)
return js.global:TraceAI(string)
end
function MoveToOwner (id)
Expand Down Expand Up @@ -53,28 +49,21 @@ define(['Vendors/lua.vm', 'Renderer/EntityManager', 'Renderer/Renderer'], functi
return js.global:GetTick()
end
function GetMsg (id)
--return js.global:GetMsg(id)
return {0}
res = {}
for i,v in ipairs(Split(js.global:GetMsg(id), ",")) do
res[i] = tonumber(v)
end
return res
end
function GetResMsg (id)
-- print('GetResMsg')
-- print(id)
-- print('GetResMsg', id)
return {0}
end
function SkillObject (id,level,skill,target)
print('SkillObject')
print(id)
print(level)
print(skill)
print(target)
print('SkillObject', id, level, skill, target)
end
function SkillGround (id,level,skill,x,y)
print('SkillGround')
print(id)
print(level)
print(skill)
print(x)
print(y)
print('SkillGround', id, level, skill, x, y)
end
function IsMonster (id)
return js.global:IsMonster(id)
Expand All @@ -93,15 +82,19 @@ define(['Vendors/lua.vm', 'Renderer/EntityManager', 'Renderer/Renderer'], functi

}

var msgPull = [];
var msg = {};

AIDriver.setmsg = function setmsg(V_, id) {
msgPull.push([V_, id])
AIDriver.setmsg = function setmsg(homId, str) {
msg[homId] = str;
}

window.GetMsg = function GetMsg(id) {
return 0;
// return msgPull.shift() ?? 0;
if (id in msg) {
let res = msg[id];
delete msg[id];
return res;
}
return '';
}

window.IsMonster = function IsMonster(id) {
Expand Down Expand Up @@ -147,11 +140,32 @@ define(['Vendors/lua.vm', 'Renderer/EntityManager', 'Renderer/Renderer'], functi
Network.sendPacket(pkt);
}

window.status = null;
window.GetActors = function () {
AIDriver.exec('js.global.status = MyState')
var res = [0]
EntityManager.forEach((item) => {
res.push(item.GID)
});

// aggressive logic
if (res.length > 3) {
if (localStorage.getItem('AGGRESSIVE') == 1) {
res.forEach((item) => {
if (item != 0 && item != Session.AID && item != Session.homunId) {
var entity = EntityManager.get(Number(item))
if (entity?.objecttype === Entity.TYPE_MOB) {
if (status == 0) { //idle = 0
// attak
AIDriver.setmsg(Session.homunId, '3,'+ item);
}
}
}
})
} else {
AIDriver.setmsg(Session.homunId, status);
}
}
return res;
}

Expand Down Expand Up @@ -224,26 +238,10 @@ define(['Vendors/lua.vm', 'Renderer/EntityManager', 'Renderer/Renderer'], functi
}

AIDriver.exec = function exec(code) {

if (!UrlExists('AI/AI.lua') || !UrlExists('AI/Util.lua') || !UrlExists('AI/Const.lua')) {
return false;
}

try {
L.execute(code);
} catch (e) {
console.error('AI_error: ', e.lua_stack);
}
}

function UrlExists(url) {
try {
var http = new XMLHttpRequest();
http.open('HEAD', url, false);
http.send();
return true;
fengari.load(code)()
} catch (e) {
return false;
console.error('AI_error: ', e);
}
}

Expand Down
53 changes: 25 additions & 28 deletions src/Engine/MapEngine/Entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ define(function( require )
var SkillActionTable = require('DB/Skills/SkillAction');
var StrEffect = require('Renderer/Effects/StrEffect');
var MiniMap = require('UI/Components/MiniMap/MiniMap');
var AllMountTable = require('DB/Jobs/AllMountTable');
var ShortCut = require('UI/Components/ShortCut/ShortCut');
var MapEffects = require('Renderer/Map/Effects');
var SpiritSphere = require('Renderer/Effects/SpiritSphere');
Expand Down Expand Up @@ -90,20 +89,19 @@ define(function( require )
else {
entity = new Entity();
entity.set(pkt);
if(pkt.job == 45){
if(MapEffects.get(pkt.GID) == null){
var mapEffect = {
'name': pkt.GID,
'pos': [pkt.PosDir[0], pkt.PosDir[1], Altitude.getCellHeight(pkt.PosDir[0], pkt.PosDir[1])],
'id': 321,
'delay': 800,
'param': [0, 0, 0, 0],
'tick': 0
};
MapEffects.add(mapEffect);
}

}
if(pkt.job == 45){
if(MapEffects.get(pkt.GID) == null){
var mapEffect = {
'name': pkt.GID,
'pos': [pkt.PosDir[0], pkt.PosDir[1], Altitude.getCellHeight(pkt.PosDir[0], pkt.PosDir[1])],
'id': 321,
'delay': 800,
'param': [0, 0, 0, 0],
'tick': 0
};
MapEffects.add(mapEffect);
}
}
EntityManager.add(entity);
}

Expand All @@ -114,7 +112,6 @@ define(function( require )
){
EffectManager.spam(6, entity.GID, entity.position);
}

}


Expand All @@ -127,9 +124,9 @@ define(function( require )
{
var entity = EntityManager.get(pkt.GID);
if (entity) {
if (entity.objecttype === Entity.TYPE_PC && pkt.GID === Session.Entity.GID) { //death animation only for myself
EffectManager.spam(372, pkt.GID);
}
if (entity.objecttype === Entity.TYPE_PC && pkt.GID === Session.Entity.GID) { //death animation only for myself
EffectManager.spam(372, pkt.GID);
}

if([2, 3].includes(pkt.type)){ //exits or teleports
EffectManager.remove(SpiritSphere, pkt.AID);
Expand Down Expand Up @@ -1037,7 +1034,7 @@ define(function( require )
}

if (srcEntity.objecttype === Entity.TYPE_PC) { //monsters don't use ACTION.SKILL animation

var action = (SkillInfo[pkt.SKID] && SkillInfo[pkt.SKID].ActionType) || 'SKILL';

srcEntity.setAction({
Expand Down Expand Up @@ -1204,7 +1201,7 @@ define(function( require )
EffectManager.spam( 215, pkt.AID);
}
break;

case StatusConst.EXPLOSIONSPIRITS: //state: 1 ON 0 OFF
case StatusConst.MARIONETTE_MASTER:
case StatusConst.MARIONETTE:
Expand Down Expand Up @@ -1246,11 +1243,11 @@ define(function( require )
EffectManager.spam( 444, pkt.AID);
}
break;

case StatusConst.TING:
EffectManager.spam( 426, pkt.AID);
break;

case StatusConst.STORMKICK_ON:
case StatusConst.STORMKICK_READY:
entity.setAction({
Expand All @@ -1261,7 +1258,7 @@ define(function( require )
next: false
});
break;

case StatusConst.DOWNKICK_ON:
case StatusConst.DOWNKICK_READY:
entity.setAction({
Expand All @@ -1272,7 +1269,7 @@ define(function( require )
next: false
});
break;

case StatusConst.TURNKICK_ON:
case StatusConst.TURNKICK_READY:
entity.setAction({
Expand All @@ -1283,7 +1280,7 @@ define(function( require )
next: false
});
break;

case StatusConst.COUNTER_ON:
case StatusConst.COUNTER_READY:
entity.setAction({
Expand All @@ -1294,7 +1291,7 @@ define(function( require )
next: false
});
break;

case StatusConst.DODGE_ON:
case StatusConst.DODGE_READY:
entity.setAction({
Expand Down Expand Up @@ -1369,7 +1366,7 @@ define(function( require )
entity.isHallucinating = false;
}
break;

case StatusConst.STOP:
if (pkt.state == 1) {
entity.attachments.add({
Expand Down
1 change: 1 addition & 0 deletions src/Network/PacketRegister.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ define( ['./PacketStructure' ], function( PACKET )
0x99d: PACKET.HC.ACCEPT_ENTER_NEO_UNION_LIST, // ok
0x9a0: PACKET.HC.CHARLIST_NOTIFY,
0x9ca: PACKET.ZC.SKILL_ENTRY5, // ok
0x9cb: PACKET.ZC.USE_SKILL2,
// 0x9d5: npcmarketopenType
// 0x9d7: npcmarketresultackType
0x9db: PACKET.ZC.NOTIFY_MOVEENTRY8, // ok
Expand Down
Loading

0 comments on commit e332233

Please sign in to comment.