add new function farm quests
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Grepolis Remote Control
|
// @name Grepolis Remote Control
|
||||||
// @namespace http://tampermonkey.net/
|
// @namespace http://tampermonkey.net/
|
||||||
// @version 3.5.7
|
// @version 3.6.0
|
||||||
// @description Polls grepo.haunter-pets.top for remote commands and executes them in-game (Multi-Player)
|
// @description Polls grepo.haunter-pets.top for remote commands and executes them in-game (Multi-Player)
|
||||||
// @author Dimitrios
|
// @author Dimitrios
|
||||||
// @match https://*.grepolis.com/game/*
|
// @match https://*.grepolis.com/game/*
|
||||||
@@ -814,6 +814,75 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Auto Bandit Camp: if enabled, attack/claim when ready
|
||||||
|
if (farmSettings.bandit_camp_enabled) {
|
||||||
|
try {
|
||||||
|
const spotModels = uw.MM.getModels().PlayerAttackSpot;
|
||||||
|
if (spotModels) {
|
||||||
|
const spotId = Object.keys(spotModels)[0];
|
||||||
|
if (spotId) {
|
||||||
|
const spot = spotModels[spotId];
|
||||||
|
const nowTs = Math.floor(Date.now() / 1000);
|
||||||
|
const townId = spot.attributes.town_id;
|
||||||
|
|
||||||
|
if (spot.attributes.reward_available) {
|
||||||
|
log('⚔️ Bandit Camp: Reward available! Waiting before claiming...');
|
||||||
|
await sleep(randInt(8000, 24000));
|
||||||
|
uw.gpAjax.ajaxPost('frontend_bridge', 'execute', {
|
||||||
|
model_url: `PlayerAttackSpot/${spotId}`,
|
||||||
|
action_name: 'useReward',
|
||||||
|
captcha: null,
|
||||||
|
arguments: {},
|
||||||
|
town_id: townId,
|
||||||
|
nl_init: true
|
||||||
|
});
|
||||||
|
log('⚔️ Bandit Camp: Reward claimed!');
|
||||||
|
} else if (spot.attributes.cooldown_at <= nowTs) {
|
||||||
|
// Check if there are active movements to make sure troops are home
|
||||||
|
let hasMovements = false;
|
||||||
|
try {
|
||||||
|
const movements = uw.MM.getOnlyCollectionByName('MovementCommand')?.models || [];
|
||||||
|
hasMovements = movements.length > 0;
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
if (!hasMovements) {
|
||||||
|
// Gather troops
|
||||||
|
const town = uw.ITowns?.getTown?.(townId) || uw.ITowns?.towns?.[townId];
|
||||||
|
if (town) {
|
||||||
|
const myUnits = town.units() || {};
|
||||||
|
const allowedUnits = ['sword', 'slinger', 'archer', 'hoplite', 'rider', 'chariot', 'catapult'];
|
||||||
|
const sendUnits = {};
|
||||||
|
let totalUnits = 0;
|
||||||
|
for (let u of allowedUnits) {
|
||||||
|
if (myUnits[u] > 0) {
|
||||||
|
sendUnits[u] = myUnits[u];
|
||||||
|
totalUnits += myUnits[u];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (totalUnits > 0) {
|
||||||
|
log(`⚔️ Bandit Camp: Cooldown over! Preparing to attack with ${totalUnits} units...`);
|
||||||
|
await sleep(randInt(8000, 24000));
|
||||||
|
uw.gpAjax.ajaxPost('frontend_bridge', 'execute', {
|
||||||
|
model_url: `PlayerAttackSpot/${spotId}`,
|
||||||
|
action_name: 'attack',
|
||||||
|
captcha: null,
|
||||||
|
arguments: sendUnits,
|
||||||
|
town_id: townId,
|
||||||
|
nl_init: true
|
||||||
|
});
|
||||||
|
log('⚔️ Bandit Camp: Attack sent!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log(`Bandit camp error: ${e.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (cmdData.sync_requested) {
|
if (cmdData.sync_requested) {
|
||||||
log('Sync requested by server — pushing state immediately');
|
log('Sync requested by server — pushing state immediately');
|
||||||
pushState();
|
pushState();
|
||||||
|
|||||||
2
db.py
2
db.py
@@ -60,6 +60,7 @@ def init_db():
|
|||||||
CREATE TABLE IF NOT EXISTS farm_settings (
|
CREATE TABLE IF NOT EXISTS farm_settings (
|
||||||
player_id TEXT PRIMARY KEY,
|
player_id TEXT PRIMARY KEY,
|
||||||
enabled INTEGER NOT NULL DEFAULT 0,
|
enabled INTEGER NOT NULL DEFAULT 0,
|
||||||
|
bandit_camp_enabled INTEGER NOT NULL DEFAULT 0,
|
||||||
loot_option INTEGER NOT NULL DEFAULT 1, -- 1=5min, 2=20min, 3=90min, 4=4h
|
loot_option INTEGER NOT NULL DEFAULT 1, -- 1=5min, 2=20min, 3=90min, 4=4h
|
||||||
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||||
)
|
)
|
||||||
@@ -73,6 +74,7 @@ def init_db():
|
|||||||
'ALTER TABLE town_state ADD COLUMN y REAL',
|
'ALTER TABLE town_state ADD COLUMN y REAL',
|
||||||
'ALTER TABLE town_state ADD COLUMN sea INTEGER',
|
'ALTER TABLE town_state ADD COLUMN sea INTEGER',
|
||||||
'ALTER TABLE commands ADD COLUMN player_id TEXT',
|
'ALTER TABLE commands ADD COLUMN player_id TEXT',
|
||||||
|
'ALTER TABLE farm_settings ADD COLUMN bandit_camp_enabled INTEGER NOT NULL DEFAULT 0',
|
||||||
]:
|
]:
|
||||||
try:
|
try:
|
||||||
c.execute(_col)
|
c.execute(_col)
|
||||||
|
|||||||
@@ -70,12 +70,12 @@ def get_farm_settings():
|
|||||||
player_id = request.args.get('player_id')
|
player_id = request.args.get('player_id')
|
||||||
conn = get_db()
|
conn = get_db()
|
||||||
row = conn.execute(
|
row = conn.execute(
|
||||||
'SELECT enabled, loot_option FROM farm_settings WHERE player_id = ?', (player_id,)
|
'SELECT enabled, bandit_camp_enabled, loot_option FROM farm_settings WHERE player_id = ?', (player_id,)
|
||||||
).fetchone()
|
).fetchone()
|
||||||
conn.close()
|
conn.close()
|
||||||
if row:
|
if row:
|
||||||
return jsonify({'enabled': bool(row['enabled']), 'loot_option': row['loot_option']})
|
return jsonify({'enabled': bool(row['enabled']), 'bandit_camp_enabled': bool(row['bandit_camp_enabled']), 'loot_option': row['loot_option']})
|
||||||
return jsonify({'enabled': False, 'loot_option': 1})
|
return jsonify({'enabled': False, 'bandit_camp_enabled': False, 'loot_option': 1})
|
||||||
|
|
||||||
@dashboard.route('/dashboard/farm-settings', methods=['POST'])
|
@dashboard.route('/dashboard/farm-settings', methods=['POST'])
|
||||||
def set_farm_settings():
|
def set_farm_settings():
|
||||||
@@ -84,16 +84,18 @@ def set_farm_settings():
|
|||||||
return jsonify({'error': 'missing player_id'}), 400
|
return jsonify({'error': 'missing player_id'}), 400
|
||||||
player_id = data['player_id']
|
player_id = data['player_id']
|
||||||
enabled = 1 if data.get('enabled') else 0
|
enabled = 1 if data.get('enabled') else 0
|
||||||
|
bandit_camp_enabled = 1 if data.get('bandit_camp_enabled') else 0
|
||||||
loot_option = int(data.get('loot_option', 1))
|
loot_option = int(data.get('loot_option', 1))
|
||||||
conn = get_db()
|
conn = get_db()
|
||||||
conn.execute('''
|
conn.execute('''
|
||||||
INSERT INTO farm_settings (player_id, enabled, loot_option, updated_at)
|
INSERT INTO farm_settings (player_id, enabled, bandit_camp_enabled, loot_option, updated_at)
|
||||||
VALUES (?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?)
|
||||||
ON CONFLICT(player_id) DO UPDATE SET
|
ON CONFLICT(player_id) DO UPDATE SET
|
||||||
enabled = excluded.enabled,
|
enabled = excluded.enabled,
|
||||||
|
bandit_camp_enabled = excluded.bandit_camp_enabled,
|
||||||
loot_option = excluded.loot_option,
|
loot_option = excluded.loot_option,
|
||||||
updated_at = excluded.updated_at
|
updated_at = excluded.updated_at
|
||||||
''', (player_id, enabled, loot_option, datetime.utcnow().isoformat()))
|
''', (player_id, enabled, bandit_camp_enabled, loot_option, datetime.utcnow().isoformat()))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
return jsonify({'ok': True})
|
return jsonify({'ok': True})
|
||||||
|
|||||||
@@ -255,6 +255,15 @@
|
|||||||
<span style="color:#888; font-size:0.85rem;" id="toggle-hint">Ανενεργό</span>
|
<span style="color:#888; font-size:0.85rem;" id="toggle-hint">Ανενεργό</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="toggle-row">
|
||||||
|
<span class="toggle-label">Στρατόπεδο Ληστών (Auto)</span>
|
||||||
|
<label class="toggle">
|
||||||
|
<input type="checkbox" id="bandit-camp-enabled">
|
||||||
|
<span class="slider"></span>
|
||||||
|
</label>
|
||||||
|
<span style="color:#888; font-size:0.85rem;" id="bandit-toggle-hint">Ανενεργό</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div style="margin-bottom: 0.75rem; font-size: 0.85rem; color: #888;">Επίπεδο Λεηλασίας:</div>
|
<div style="margin-bottom: 0.75rem; font-size: 0.85rem; color: #888;">Επίπεδο Λεηλασίας:</div>
|
||||||
<div class="option-grid">
|
<div class="option-grid">
|
||||||
<button class="option-btn selected" data-option="1">
|
<button class="option-btn selected" data-option="1">
|
||||||
@@ -337,27 +346,36 @@
|
|||||||
// -- Toggle hint text --
|
// -- Toggle hint text --
|
||||||
document.getElementById('farm-enabled').addEventListener('change', function () {
|
document.getElementById('farm-enabled').addEventListener('change', function () {
|
||||||
document.getElementById('toggle-hint').textContent = this.checked ? '🟢 Ενεργό' : 'Ανενεργό';
|
document.getElementById('toggle-hint').textContent = this.checked ? '🟢 Ενεργό' : 'Ανενεργό';
|
||||||
updateStatusBar(this.checked);
|
updateStatusBar(this.checked, document.getElementById('bandit-camp-enabled').checked);
|
||||||
});
|
});
|
||||||
|
|
||||||
function updateStatusBar(enabled) {
|
document.getElementById('bandit-camp-enabled').addEventListener('change', function () {
|
||||||
|
document.getElementById('bandit-toggle-hint').textContent = this.checked ? '🟢 Ενεργό' : 'Ανενεργό';
|
||||||
|
updateStatusBar(document.getElementById('farm-enabled').checked, this.checked);
|
||||||
|
});
|
||||||
|
|
||||||
|
function updateStatusBar(farmEnabled, banditEnabled) {
|
||||||
const bar = document.getElementById('status-bar');
|
const bar = document.getElementById('status-bar');
|
||||||
if (enabled) {
|
if (farmEnabled || banditEnabled) {
|
||||||
bar.className = 'status-bar visible';
|
bar.className = 'status-bar visible';
|
||||||
bar.textContent = '🤖 Ο αυτόματος farmer είναι ενεργός. Το script θα λεηλατεί χωριά με τυχαίες καθυστερήσεις.';
|
let msg = [];
|
||||||
|
if (farmEnabled) msg.push('Ο αυτόματος farmer είναι ενεργός.');
|
||||||
|
if (banditEnabled) msg.push('Το στρατόπεδο ληστών είναι ενεργό.');
|
||||||
|
bar.textContent = '🤖 ' + msg.join(' ') + ' Το script θα εκτελεί δράσεις με τυχαίες καθυστερήσεις.';
|
||||||
} else {
|
} else {
|
||||||
bar.className = 'status-bar visible off';
|
bar.className = 'status-bar visible off';
|
||||||
bar.textContent = '⏸ Η αυτόματη λεηλασία είναι ανενεργή.';
|
bar.textContent = '⏸ Οι αυτόματες ενέργειες είναι ανενεργές.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- Save settings --
|
// -- Save settings --
|
||||||
function saveSettings() {
|
function saveSettings() {
|
||||||
const enabled = document.getElementById('farm-enabled').checked;
|
const enabled = document.getElementById('farm-enabled').checked;
|
||||||
|
const bandit_camp_enabled = document.getElementById('bandit-camp-enabled').checked;
|
||||||
fetch('/dashboard/farm-settings', {
|
fetch('/dashboard/farm-settings', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ player_id: PLAYER_ID, enabled, loot_option: selectedOption })
|
body: JSON.stringify({ player_id: PLAYER_ID, enabled, bandit_camp_enabled, loot_option: selectedOption })
|
||||||
})
|
})
|
||||||
.then(r => r.json())
|
.then(r => r.json())
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@@ -373,8 +391,13 @@
|
|||||||
.then(r => r.json())
|
.then(r => r.json())
|
||||||
.then(cfg => {
|
.then(cfg => {
|
||||||
document.getElementById('farm-enabled').checked = cfg.enabled;
|
document.getElementById('farm-enabled').checked = cfg.enabled;
|
||||||
|
document.getElementById('bandit-camp-enabled').checked = cfg.bandit_camp_enabled || false;
|
||||||
|
|
||||||
document.getElementById('toggle-hint').textContent = cfg.enabled ? '🟢 Ενεργό' : 'Ανενεργό';
|
document.getElementById('toggle-hint').textContent = cfg.enabled ? '🟢 Ενεργό' : 'Ανενεργό';
|
||||||
if (cfg.enabled) updateStatusBar(true);
|
document.getElementById('bandit-toggle-hint').textContent = cfg.bandit_camp_enabled ? '🟢 Ενεργό' : 'Ανενεργό';
|
||||||
|
|
||||||
|
updateStatusBar(cfg.enabled, cfg.bandit_camp_enabled);
|
||||||
|
|
||||||
selectedOption = cfg.loot_option || 1;
|
selectedOption = cfg.loot_option || 1;
|
||||||
document.querySelectorAll('.option-btn').forEach(b => {
|
document.querySelectorAll('.option-btn').forEach(b => {
|
||||||
b.classList.toggle('selected', parseInt(b.dataset.option) === selectedOption);
|
b.classList.toggle('selected', parseInt(b.dataset.option) === selectedOption);
|
||||||
|
|||||||
Reference in New Issue
Block a user